********************* PREPARATION FOR MAIN ANALYSES

*** Set working directory (you will need to configure this for your computer); within this folder, there is a subfolder "Datasets" containing all datasets used in the analysis, as well as holder subfolders to output figures and tables
cd "INSERT RELEVANT WORKING DIRECTORY"



*** Set relevant version of Stata and increase matrix size
version 17
set matsize 11000



*** Open Stata log
log using "Replication_Results_Log.smcl", replace



*** Open main data
use "Datasets\Main_Precinct_Dataset.dta", clear



*** Data preparation
** Note that electoral returns do not exist in two municipalities (Oxchuc, Chiapas and Ayutla de los Libres, Guerrero) because they adopted a customary system for selecting their mayors without elections

** Drop the block containing only 2 municipalities (this is later reinstated with appropriate inverse probability of assignments weights for robustness)
drop if block_size==2

** Compute segment-level weights to account for a segment's inverse probability of assignment to treatment
* Weights for regressions that do not pool over the common knowledge treatment
g full_prob = 1/3
replace full_prob = 1/3 * 2/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==3
replace full_prob = 1/3 * 1/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==3
replace full_prob = 1/3 * 1/10 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==2
replace full_prob = 1/3 * 4/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==2
replace full_prob = 1/2 * 1/6 if facebook_treatment==1 & saturation_treatment==2 & number_of_segments==3
replace full_prob = 1/2 * 2/3 if facebook_treatment==0 & saturation_treatment==2 & number_of_segments==3

* Weights for regressions that pool over the common knowledge treatment
g pooled_CK_prob = 1/3
replace pooled_CK_prob = 1/3 * 4/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==3
replace pooled_CK_prob = 1/3 * 1/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==3
replace pooled_CK_prob = 1/3 * 1/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==2
replace pooled_CK_prob = 1/3 * 4/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==2
replace pooled_CK_prob = 1/2 * 1/3 if facebook_treatment==1 & saturation_treatment==2 & number_of_segments==3
replace pooled_CK_prob = 1/2 * 2/3 if facebook_treatment==0 & saturation_treatment==2 & number_of_segments==3

* Weights for regressions that pool over saturation level
g pooled_sat_prob = 1/3
replace pooled_sat_prob = 2/3 * 1/4 if (facebook_treatment==1 | facebook_common_treatment==1) & (saturation_treatment==2 | saturation_treatment==3)
replace pooled_sat_prob = 2/3 * 1/2 if (facebook_treatment==0 & facebook_common_treatment==0) & (saturation_treatment==2 | saturation_treatment==3)
replace pooled_sat_prob = 1/2 * 1/6 if facebook_treatment==1 & number_of_segments==3
replace pooled_sat_prob = 1/2 * 2/3 if facebook_treatment==0 & number_of_segments==3

* Weights for regressions that pool over the common knowledge treatment and saturation level
g pooled_CK_sat_prob = 1/3
replace pooled_CK_sat_prob = 2/3 * 1/2 if (facebook_treatment==1 | facebook_common_treatment==1) & (saturation_treatment==2 | saturation_treatment==3)
replace pooled_CK_sat_prob = 2/3 * 1/2 if (facebook_treatment==0 & facebook_common_treatment==0) & (saturation_treatment==2 | saturation_treatment==3)
replace pooled_CK_sat_prob = 1/2 * 1/3 if facebook_treatment==1 & number_of_segments==3
replace pooled_CK_sat_prob = 1/2 * 2/3 if facebook_treatment==0 & number_of_segments==3

* Compute number of registered voters by segment and municipality among precincts with available data
bysort code_INEGI segment : egen seg_listanominal_2018 = sum(muni_listanominal_2018)
bysort code_INEGI : egen mun_listanominal_2018 = sum(muni_listanominal_2018)

* Compute final weights for regressions
g segment_full_weight = muni_listanominal_2018 / (full_prob * seg_listanominal_2018)
g segment_pooled_CK_weight = muni_listanominal_2018 / (pooled_CK_prob * seg_listanominal_2018)
g segment_pooled_sat_weight = muni_listanominal_2018 / (pooled_sat_prob * seg_listanominal_2018)
g segment_pooled_CK_sat_weight = muni_listanominal_2018 / (pooled_CK_sat_prob * seg_listanominal_2018)
g segment_weight = muni_listanominal_2018 / ((1/block_size) * seg_listanominal_2018)
g municipal_weight = muni_listanominal_2018 / ((1/block_size) * mun_listanominal_2018)

** Define main treatment conditions
g any_facebook_treatment = facebook_treatment==1 | facebook_common_treatment==1
label define d_new_values 0 "Control" 1 "Direct effect"
label values any_facebook_treatment d_new_values
g any_saturation_treatment = saturation_treatment!=1
label define any_saturation_treatment 0 "Control" 1 "Any Saturation"
label values any_saturation_treatment any_saturation_treatment
g spillover = saturation_treatment!=1 & any_facebook_treatment==0
label define i_new_values 0 "Control" 1 "Indirect effect"
label values spillover i_new_values
g facebook_saturation = 0
replace facebook_saturation = 1 if any_facebook_treatment==0 & saturation_treatment==2
replace facebook_saturation = 2 if any_facebook_treatment==1 & saturation_treatment==2
replace facebook_saturation = 3 if any_facebook_treatment==0 & saturation_treatment==3
replace facebook_saturation = 4 if any_facebook_treatment==1 & saturation_treatment==3
label define new_values 0 "Control" 1 "Indirect effect in low saturation" 2 "Direct effect in low saturation" 3 "Indirect effect in high saturation" 4 "Direct effect in high saturation"
label values facebook_saturation new_values
g facebook_full_saturation = 0
replace facebook_full_saturation = 1 if any_facebook_treatment==0 & saturation_treatment==2
replace facebook_full_saturation = 2 if facebook_treatment==1 & saturation_treatment==2
replace facebook_full_saturation = 3 if facebook_common_treatment==1 & saturation_treatment==2
replace facebook_full_saturation = 4 if any_facebook_treatment==0 & saturation_treatment==3
replace facebook_full_saturation = 5 if facebook_treatment==1 & saturation_treatment==3
replace facebook_full_saturation = 6 if facebook_common_treatment==1 & saturation_treatment==3
label define facebook_full_saturation_2 0 "Control" 1 "Indirect effect in low saturation" 2 "Direct effect in low saturation" 3 "Direct effect + CK in low saturation" 4 "Indirect effect in high saturation" 5 "Direct effect in high saturation" 6 "Direct effect + CK in high saturation"
label values facebook_full_saturation facebook_full_saturation_2

** Compute malfeasance classifications within the sample
sum share_irregularities_audited [aweight=municipal_weight], det
g quartiles = 1
replace quartiles = 3 if share_irreg>`r(p50)' & share_irreg<=`r(p75)'
replace quartiles = 4 if share_irreg>`r(p75)'
cap label define quartile 1 "Irregularities Q1/Q2" 3 "Irregularities Q3" 4 "Irregularities Q4"
label values quartiles quartile
g above_malf_median = quartiles==3 | quartiles==4 if quartiles!=.
cap label define median 0 "Below-median irregularities" 1 "Above-median irregularities"
label values above_malf_median median






********************* TABLES AND FIGURES IN THE MAIN PAPER

*** Figure 2: Distribution of irregularities across municipalities in our sample
preserve
quietly {
	use "Datasets\Randomized_Municipal_Saturations.dta", clear
	drop if block_size==2
	sum share_irreg, det
	histogram share_irreg, bin(20) frequency fcolor(gray) lcolor(gray) ytitle("Number of municipalities") ylabel(0 (20) 110, nogrid) xline(`r(p50)', lcolor(red)) xline(`r(p75)', lcolor(red)) ///
		xtitle("Irregularities as a share of audited funds") legend(off) graphregion(margin(zero) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) addlabel 
	graph export "Figures\treatment_distribution_with_quartiles.pdf", as(pdf) replace
}
restore



*** Table 1: Exposure to and engagement with Facebook ad campaigns, by municipal saturation
quietly {
	preserve
	use "Datasets\facebook_ads.dta", clear
	duplicates drop code_INEGI, force
	** Run regressions and make tables
	** Panel A: levels of exposure and engagement by municipal saturation level
	eststo clear
	foreach x of varlist PaidImpressions Organicimpressions PaidReach OrganicReach PageEngagedUsers TotalVideoViews TotalUniqueVideoViews muni_watched_10_seconds ///
			muni_watched_10_seconds_unique Total30SecondViews TotalUnique30SecondV {
		replace `x' = 0 if `x'==.
		eststo, title("`x'") : reg `x' i.saturation_treatment if saturation_treatment>1, ro
		sum `x' if e(sample) & saturation_treatment==2
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 4 * _cons == (_cons + 3.saturation_treatment)
		estadd scalar F_test_2 = `r(p)'
	}
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome F_test_2, fmt(%9.0fc 2 2 2 3) ///
		labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev." "Test: 4 * Low saturation = High saturation ($ p$ value, 2-sided)")) ///
		starlevels(* .1 ** .05 *** .01) keep(3.saturation_treatment) label varlabel(3.saturation_treatment "High saturation") order(3.saturation_treatment*) 
	esttab est* using "Tables\first_stage_3_no_control.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome F_test_2, fmt(%9.0fc 2 2 2 3) ///
		labels("Observations" "$ R^2$" "%Low saturation outcome mean" "%Low saturation outcome std. dev." "Test: 4 * Low saturation = High saturation ($ p$ value, 2-sided)")) ///
		starlevels(* .1 ** .05 *** .01) keep(3.saturation_treatment) label varlabel(3.saturation_treatment "High saturation") order(3.saturation_treatment*) replace
	** Panel B: heterogeneity by municipal irregularities above and below the sample median
	eststo clear
	foreach x of varlist PaidImpressions Organicimpressions PaidReach OrganicReach PageEngagedUsers TotalVideoViews TotalUniqueVideoViews muni_watched_10_seconds ///
			muni_watched_10_seconds_unique Total30SecondViews TotalUnique30SecondV {
		replace `x' = 0 if `x'==.
		eststo, title("`x'") : reg `x' i.saturation_treatment##above_malf_median if saturation_treatment>1, ro
		sum `x' if e(sample) & saturation_treatment==2
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
	}
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
		labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev.")) starlevels(* .1 ** .05 *** .01) keep(1.above_malf_median 3.saturation_treatment*) ///
		drop(*0.above_malf_median) label varlabel(3.saturation_treatment "High saturation") order(1.above_malf_median 3.saturation_treatment*) 
	esttab est* using "Tables\first_stage_by_median_3_no_control.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
		labels("%Observations" "$ R^2$" "%Low saturation outcome mean" "%Low saturation outcome std. dev.")) starlevels(* .1 ** .05 *** .01) keep(1.above_malf_median 3.saturation_treatment*) ///
		drop(*0.above_malf_median) label varlabel(3.saturation_treatment "High saturation") order(1.above_malf_median 3.saturation_treatment*) replace
	restore
}



*** Table 2: Effect of Facebook ads on precinct-level municipal incumbent party vote share and electoral turnout
quietly {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment spillover [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment spillover [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	** Regressions
	eststo clear
	foreach x in muni_inc_vote_share muni_turnout {
		* ATE, no interactive controls
		eststo, title("`x'") : areg `x'_2018 `x'_2015 1.any_facebook_treatment 1.spillover [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		* Facebook and spillover effects by median, no interactive controls
		eststo, title("`x'") : areg `x'_2018 `x'_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
			[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 1.any_facebook_treatment = 0
		estadd scalar F_test_1a = `r(p)'
		test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
		estadd scalar F_test_1b = `r(p)'
		test 1.spillover + 1.spillover = 0
		estadd scalar F_test_3a = `r(p)'
		test 1.spillover + 1.spillover#1.above_malf_median = 0
		estadd scalar F_test_3b = `r(p)'
		* Facebook and spillover effects by median, interactive controls
		eststo, title("`x'") : areg `x'_2018 `x'_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median $any_facebook_treatment_controls $spillover_controls ///
			[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 1.any_facebook_treatment = 0
		estadd scalar F_test_1a = `r(p)'
		test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
		estadd scalar F_test_1b = `r(p)'
		test 1.spillover + 1.spillover = 0
		estadd scalar F_test_3a = `r(p)'
		test 1.spillover + 1.spillover#1.above_malf_median = 0
		estadd scalar F_test_3b = `r(p)'
	}
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_3a F_test_3b, fmt(%9.0fc %9.0fc 2 2 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." "Test: null effect of direct effect below median ($ p$ value)" ///
		"Test: null effect of direct effect above median ($ p$ value)" "Test: null effect of indirect effect below median ($ p$ value)" "Test: null effect of indirect effect above median ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover*) label ///
		varlabel(1.any_facebook_treatment "Direct effect" 1.spillover "Indirect effect" 1.any_facebook_treatment#1.above_malf_median "Direct effect $\times$ Above-median irregularities" ///
		1.spillover#1.above_malf_median "Indirect effect $\times$ Above-median irregularities" ) drop(0.* *control* *0.above_malf_median) order(*any_facebook_treatment* *spillover*)
	esttab est* using "Tables\HEs_vote_turnout_by_median.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_3a F_test_3b, fmt(%9.0fc %9.0fc 2 2 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." "Test: null effect of direct effect below median ($ p$ value)" ///
		"Test: null direct effect above median ($ p$ value)" "Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover*) label ///
		varlabel(1.any_facebook_treatment "Direct effect" 1.spillover "Indirect effect" 1.any_facebook_treatment#1.above_malf_median "Direct effect $\times$ Above-median irregularities" ///
		1.spillover#1.above_malf_median "Indirect effect $\times$ Above-median irregularities" ) drop(0.* *control* *0.above_malf_median) order(*any_facebook_treatment* *spillover*) replace
	restore
}



*** Figure 4: Conditional average treatment effects of Facebook ads on incumbent party vote share, below and above median irregularities
quietly {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_sat_weight], ///
		cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_sat_weight], ///
		cluster(code_INEGI) a(id_block)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	** Save coefficients from regressions
	matrix U = J(8,7,0)
	foreach x of numlist 1/8 {
		matrix U[`x',1] = `x'
		matrix U[`x',5] = 1
	}
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_sat_weight], ///
		cluster(code_INEGI) a(id_block)
	matrix U[1,2] = _b[1.any_facebook_treatment]
	matrix U[1,3] = _b[1.any_facebook_treatment] - 1.96 * _se[1.any_facebook_treatment]
	matrix U[1,4] = _b[1.any_facebook_treatment] + 1.96 * _se[1.any_facebook_treatment]
	matrix U[1,6] = _b[1.any_facebook_treatment] - 1.645 * _se[1.any_facebook_treatment]
	matrix U[1,7] = _b[1.any_facebook_treatment] + 1.645 * _se[1.any_facebook_treatment]
	matrix U[2,2] = _b[1.spillover]
	matrix U[2,3] = _b[1.spillover] - 1.96 * _se[1.spillover]
	matrix U[2,4] = _b[1.spillover] + 1.96 * _se[1.spillover]
	matrix U[2,6] = _b[1.spillover] - 1.645 * _se[1.spillover]
	matrix U[2,7] = _b[1.spillover] + 1.645 * _se[1.spillover]
	matrix U[3,2] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median]
	lincom 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median
	matrix U[3,3] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median] - 1.96 * `r(se)'
	matrix U[3,4] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median] + 1.96 * `r(se)'
	matrix U[3,6] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median] - 1.645 * `r(se)'
	matrix U[3,7] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median] + 1.645 * `r(se)'
	matrix U[3,5] = 2
	matrix U[4,2] = _b[1.spillover] + _b[1.spillover#1.above_malf_median]
	lincom 1.spillover + 1.spillover#1.above_malf_median
	matrix U[4,3] = _b[1.spillover] + _b[1.spillover#1.above_malf_median] - 1.96 * `r(se)'
	matrix U[4,4] = _b[1.spillover] + _b[1.spillover#1.above_malf_median] + 1.96 * `r(se)'
	matrix U[4,6] = _b[1.spillover] + _b[1.spillover#1.above_malf_median] - 1.645 * `r(se)'
	matrix U[4,7] = _b[1.spillover] + _b[1.spillover#1.above_malf_median] + 1.645 * `r(se)'
	matrix U[4,5] = 2
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
		$any_facebook_treatment_controls $spillover_controls [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	matrix U[5,2] = _b[1.any_facebook_treatment]
	matrix U[5,3] = _b[1.any_facebook_treatment] - 1.96 * _se[1.any_facebook_treatment]
	matrix U[5,4] = _b[1.any_facebook_treatment] + 1.96 * _se[1.any_facebook_treatment]
	matrix U[5,6] = _b[1.any_facebook_treatment] - 1.645 * _se[1.any_facebook_treatment]
	matrix U[5,7] = _b[1.any_facebook_treatment] + 1.645 * _se[1.any_facebook_treatment]
	matrix U[6,2] = _b[1.spillover]
	matrix U[6,3] = _b[1.spillover] - 1.96 * _se[1.spillover]
	matrix U[6,4] = _b[1.spillover] + 1.96 * _se[1.spillover]
	matrix U[6,6] = _b[1.spillover] - 1.645 * _se[1.spillover]
	matrix U[6,7] = _b[1.spillover] + 1.645 * _se[1.spillover]
	matrix U[7,2] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median]
	lincom 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median
	matrix U[7,3] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median] - 1.96 * `r(se)'
	matrix U[7,4] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median] + 1.96 * `r(se)'
	matrix U[7,6] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median] - 1.645 * `r(se)'
	matrix U[7,7] = _b[1.any_facebook_treatment] + _b[1.any_facebook_treatment#1.above_malf_median] + 1.645 * `r(se)'
	matrix U[7,5] = 2
	matrix U[8,2] = _b[1.spillover] + _b[1.spillover#1.above_malf_median]
	lincom 1.spillover + 1.spillover#1.above_malf_median
	matrix U[8,3] = _b[1.spillover] + _b[1.spillover#1.above_malf_median] - 1.96 * `r(se)'
	matrix U[8,4] = _b[1.spillover] + _b[1.spillover#1.above_malf_median] + 1.96 * `r(se)'
	matrix U[8,6] = _b[1.spillover] + _b[1.spillover#1.above_malf_median] - 1.645 * `r(se)'
	matrix U[8,7] = _b[1.spillover] + _b[1.spillover#1.above_malf_median] + 1.645 * `r(se)'
	matrix U[8,5] = 2
	matrix colnames U = "order" "coef" "lower" "upper" "Median" "lower2" "upper2"
	matrix list U
	svmat U, names(col)
	** Make figures
	g placement = Median - 0.07 if order<=4
	replace placement = Median + 0.07 if order>4
	g condition = .
	replace condition = 4 if order==6 | order==8
	replace condition = 3 if order==5 | order==7
	replace condition = 2 if order==2 | order==4
	replace condition = 1 if order==1 | order==3
	cap label define condition_simple 4 "Spillover (adjusted)" 3 "Facebook ads (adjusted)" 2 "Spillover" 1 "Facebook ads"
	label values condition condition_simple
	twoway (scatter coef placement if condition==1, mcolor(black) msize(large)) (rcap lower upper placement if condition==1, vertical lcolor(black) lwidth(medium) msize(zero)) ///
		(rcap lower2 upper2 placement if condition==1, vertical lcolor(black) lwidth(thick) msize(zero)) (scatter coef placement if condition==3, mcolor(blue) msize(large)) ///
		(rcap lower upper placement if condition==3, vertical lcolor(blue) lwidth(medium) msize(zero)) (rcap lower2 upper2 placement if condition==3, vertical lcolor(blue) lwidth(thick) msize(zero)), ///
		graphregion(margin(zero) fcolor(white) lcolor(white) lwidth(none) ifcolor(white) ilcolor(white)) subtitle(, color(black) nobox) title("") ///
		legend(order(3 "Unadjusted" 6 "Covariate adjusted") position(6) region(fcolor(white) lcolor(white)) size(large)) ///
		yscale(range(-.08 .16)) ylab(-.05(.05).15) xscale(range(0.5 2.5)) xlab(1 "Below-median" 2 "Above-median", valuelabel nogrid labsize(large)) ///
		ylab(, nogrid labsize(medlarge)) yline(0, lcolor(black) lpattern(dash)) ///
		ytitle("Direct effect on vote share", size(large)) xtitle("Position in irregularities distribution", size(large)) xscale(titlegap(2)) yscale(titlegap(1)) bgcolor(white)
	graph export "Figures\direct_effects_by_median.pdf", as(pdf) replace
	twoway (scatter coef placement if condition==2, mcolor(black) msize(large)) (rcap lower upper placement if condition==2, vertical lcolor(black) lwidth(medium) msize(zero)) ///
		(rcap lower2 upper2 placement if condition==2, vertical lcolor(black) lwidth(thick) msize(zero)) (scatter coef placement if condition==4, mcolor(blue) msize(large)) ///
		(rcap lower upper placement if condition==4, vertical lcolor(blue) lwidth(medium) msize(zero)) (rcap lower2 upper2 placement if condition==4, vertical lcolor(blue) lwidth(thick) msize(zero)), ///
		graphregion(margin(zero) fcolor(white) lcolor(white) lwidth(none) ifcolor(white) ilcolor(white)) subtitle(, color(black) nobox) title("") ///
		legend(order(3 "Unadjusted" 6 "Covariate adjusted") position(6) region(fcolor(white) lcolor(white)) size(large)) ///
		yscale(range(-.06 .105)) ylab(-.05(.05).1) xscale(range(0.5 2.5)) xlab(1 "Below-median" 2 "Above-median", valuelabel nogrid labsize(large)) ///
		ylab(, nogrid labsize(medlarge)) yline(0, lcolor(black) lpattern(dash)) ///
		ytitle("Indirect effect on vote share", size(large)) xtitle("Position in irregularities distribution", size(large)) xscale(titlegap(2)) yscale(titlegap(1)) bgcolor(white)
	graph export "Figures\indirect_effects_by_median.pdf", as(pdf) replace
	restore
}



*** Table 3: Effect of Facebook ads on precinct-level municipal incumbent party vote share and electoral turnout, by information campaign saturation
quietly {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	** Regressions
	eststo clear
	quietly foreach x in muni_inc_vote_share muni_turnout {
		* Facebook and spillover effects by saturation
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 4.facebook_saturation == 2.facebook_saturation
		estadd scalar F_test_1 = `r(p)'
		test 3.facebook_saturation == 1.facebook_saturation
		estadd scalar F_test_2 = `r(p)'
		* Facebook and spillover effects by saturation and median
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 4.facebook_saturation == 2.facebook_saturation
		estadd scalar F_test_5 = `r(p)'
		test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
		estadd scalar F_test_3 = `r(p)'
		test 3.facebook_saturation == 1.facebook_saturation
		estadd scalar F_test_8 = `r(p)'
		test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
		estadd scalar F_test_4 = `r(p)'
		* Facebook and spillover effects by saturation and median, interactive controls
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation##above_malf_median $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 4.facebook_saturation == 2.facebook_saturation
		estadd scalar F_test_5 = `r(p)'
		test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
		estadd scalar F_test_3 = `r(p)'
		test 3.facebook_saturation == 1.facebook_saturation
		estadd scalar F_test_8 = `r(p)'
		test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
		estadd scalar F_test_4 = `r(p)'
	}
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1 F_test_5 F_test_3 F_test_2 F_test_8 F_test_4, ///
		fmt(%9.0fc %9.0fc 2) labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: same direct effect under high and low saturation ($ p$ value)" "Test: same direct effect under high and low saturation below median ($ p$ value)" ///
		"Test: same direct effect under high and low saturation above median ($ p$ value)" "Test: same indirect effect under high and low saturation ($ p$ value)" ///
		"Test: same indirect effect under high and low saturation below median ($ p$ value)" "Test: same indirect effect under high and low saturation above median ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*facebook_saturation*) label ///
		varlabel(1.facebook_saturation "Indirect effect in low saturation" 2.facebook_saturation "Direct effect in low saturation" ///
		3.facebook_saturation "Indirect effect in high saturation" 4.facebook_saturation "Direct effect in high saturation" ///
		1.facebook_saturation#1.above_malf_median "Indirect effect in low saturation $\times$ Above-median irregularities" ///
		2.facebook_saturation#1.above_malf_median "Direct effect in low saturation $\times$ Above-median irregularities" ///
		3.facebook_saturation#1.above_malf_median "Indirect effect in high saturation $\times$ Above-median irregularities" ///
		4.facebook_saturation#1.above_malf_median "Direct effect in high saturation $\times$ Above-median irregularities") ///
		drop(0.* *control* *0.above_malf_median) order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*)
	esttab est* using "Tables\HEs_vote_turnout_by_median_and_saturation.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1 F_test_5 F_test_3 F_test_2 F_test_8 F_test_4, ///
		fmt(%9.0fc %9.0fc 2) labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: same direct effect under high and low saturation ($ p$ value)" "Test: same direct effect under high and low saturation below median ($ p$ value)" ///
		"Test: same direct effect under high and low saturation above median ($ p$ value)" "Test: same indirect effect under high and low saturation ($ p$ value)" ///
		"Test: same indirect effect under high and low saturation below median ($ p$ value)" "Test: same indirect effect under high and low saturation above median ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*facebook_saturation*) label ///
		varlabel(1.facebook_saturation "Indirect effect in low saturation" 2.facebook_saturation "Direct effect in low saturation" ///
		3.facebook_saturation "Indirect effect in high saturation" 4.facebook_saturation "Direct effect in high saturation" ///
		1.facebook_saturation#1.above_malf_median "Indirect effect in low saturation $\times$ Above-median irregularities" ///
		2.facebook_saturation#1.above_malf_median "Direct effect in low saturation $\times$ Above-median irregularities" ///
		3.facebook_saturation#1.above_malf_median "Indirect effect in high saturation $\times$ Above-median irregularities" ///
		4.facebook_saturation#1.above_malf_median "Direct effect in high saturation $\times$ Above-median irregularities") ///
		drop(0.* *control* *0.above_malf_median) order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
	restore
}



*** Figure 5: Conditional average treatment effects of Facebook ads on incumbent party vote share in municipalities with below-median irregularities, by ad campaign saturation

** (a) Direct effect
quietly {
	preserve
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	* Save coefficients from regressions
	matrix U = J(4,7,0)
	foreach x of numlist 1/4 {
		matrix U[`x',1] = `x'
		matrix U[`x',5] = 1
	}
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	lincom 4.facebook_saturation
	matrix U[1,2] = `r(estimate)'
	matrix U[1,3] = `r(estimate)' - 1.96 * `r(se)'
	matrix U[1,4] = `r(estimate)' + 1.96 * `r(se)'
	matrix U[1,6] = `r(estimate)' - 1.645 * `r(se)'
	matrix U[1,7] = `r(estimate)' + 1.645 * `r(se)'
	lincom 2.facebook_saturation
	matrix U[2,2] = `r(estimate)'
	matrix U[2,3] = `r(estimate)' - 1.96 * `r(se)'
	matrix U[2,4] = `r(estimate)' + 1.96 * `r(se)'
	matrix U[2,5] = 2
	matrix U[2,6] = `r(estimate)' - 1.645 * `r(se)'
	matrix U[2,7] = `r(estimate)' + 1.645 * `r(se)'
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	lincom 4.facebook_saturation
	matrix U[3,2] = `r(estimate)'
	matrix U[3,3] = `r(estimate)' - 1.96 * `r(se)'
	matrix U[3,4] = `r(estimate)' + 1.96 * `r(se)'
	matrix U[3,6] = `r(estimate)' - 1.645 * `r(se)'
	matrix U[3,7] = `r(estimate)' + 1.645 * `r(se)'
	lincom 2.facebook_saturation
	matrix U[4,2] = `r(estimate)'
	matrix U[4,3] = `r(estimate)' - 1.96 * `r(se)'
	matrix U[4,4] = `r(estimate)' + 1.96 * `r(se)'
	matrix U[4,5] = 2
	matrix U[4,6] = `r(estimate)' - 1.645 * `r(se)'
	matrix U[4,7] = `r(estimate)' + 1.645 * `r(se)'
	matrix colnames U = "order" "coef" "lower" "upper" "Saturation" "lower2" "upper2"
	matrix list U
	svmat U, names(col)
	* Make figure
	g placement = Saturation - 0.07 if order<=2
	replace placement = Saturation + 0.07 if order>2
	g condition = .
	replace condition = 2 if order==3 | order==4
	replace condition = 1 if order==1 | order==2
	cap label define condition_simple 2 "Direct (adjusted)" 1 "Direct"
	label values condition condition_simple
	twoway (scatter coef placement if condition==1, mcolor(black) msize(large)) (rcap lower upper placement if condition==1, ///
		vertical lcolor(black) lwidth(medium) msize(zero)) (rcap lower2 upper2 placement if condition==1, vertical lcolor(black) lwidth(thick) msize(zero)) ///
		(scatter coef placement if condition==2, mcolor(blue) msize(large)) (rcap lower upper placement if condition==2, ///
		vertical lcolor(blue) lwidth(medium) msize(zero)) (rcap lower2 upper2 placement if condition==2, vertical lcolor(blue) lwidth(thick) msize(zero)), ///
		graphregion(margin(zero) fcolor(white) lcolor(white) lwidth(none) ifcolor(white) ilcolor(white)) subtitle(, color(black) nobox) title("") ///
		legend(order(3 "Unadjusted" 6 "Covariate adjusted") position(6) region(fcolor(white) lcolor(white)) size(large)) xscale(titlegap(2)) yscale(titlegap(1)) bgcolor(white) ///
		yscale(range(-.06 .16)) ylab(-.05(.05).15) xscale(range(0.5 2.5)) xlab(1 "High" 2 "Low", valuelabel nogrid labsize(large)) ///
		ylab(, nogrid labsize(medlarge)) yline(0, lcolor(black) lpattern(dash)) ytitle("Treatment effect on vote share", size(large)) xtitle("Municipal saturation", size(large)) 
	graph export "Figures\direct_effects_below_median_by_saturation.pdf", as(pdf) replace
	restore
}

** (b) Indirect effect
quietly {
	preserve
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	* Save coefficients from regressions
	matrix U = J(4,7,0)
	foreach x of numlist 1/4 {
		matrix U[`x',1] = `x'
		matrix U[`x',5] = 1
	}
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	lincom 3.facebook_saturation
	matrix U[1,2] = `r(estimate)'
	matrix U[1,3] = `r(estimate)' - 1.96 * `r(se)'
	matrix U[1,4] = `r(estimate)' + 1.96 * `r(se)'
	matrix U[1,6] = `r(estimate)' - 1.645 * `r(se)'
	matrix U[1,7] = `r(estimate)' + 1.645 * `r(se)'
	lincom 1.facebook_saturation
	matrix U[2,2] = `r(estimate)'
	matrix U[2,3] = `r(estimate)' - 1.96 * `r(se)'
	matrix U[2,4] = `r(estimate)' + 1.96 * `r(se)'
	matrix U[2,5] = 2
	matrix U[2,6] = `r(estimate)' - 1.645 * `r(se)'
	matrix U[2,7] = `r(estimate)' + 1.645 * `r(se)'
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	lincom 3.facebook_saturation
	matrix U[3,2] = `r(estimate)'
	matrix U[3,3] = `r(estimate)' - 1.96 * `r(se)'
	matrix U[3,4] = `r(estimate)' + 1.96 * `r(se)'
	matrix U[3,6] = `r(estimate)' - 1.645 * `r(se)'
	matrix U[3,7] = `r(estimate)' + 1.645 * `r(se)'
	lincom 1.facebook_saturation
	matrix U[4,2] = `r(estimate)'
	matrix U[4,3] = `r(estimate)' - 1.96 * `r(se)'
	matrix U[4,4] = `r(estimate)' + 1.96 * `r(se)'
	matrix U[4,5] = 2
	matrix U[4,6] = `r(estimate)' - 1.645 * `r(se)'
	matrix U[4,7] = `r(estimate)' + 1.645 * `r(se)'
	matrix colnames U = "order" "coef" "lower" "upper" "Saturation" "lower2" "upper2"
	matrix list U
	svmat U, names(col)
	* Make figure
	g placement = Saturation - 0.07 if order<=2
	replace placement = Saturation + 0.07 if order>2
	g condition = .
	replace condition = 2 if order==3 | order==4
	replace condition = 1 if order==1 | order==2
	cap label define condition_simple 2 "Spillover (adjusted)" 1 "Spillover"
	label values condition condition_simple
	twoway (scatter coef placement if condition==1, mcolor(black) msize(large)) (rcap lower upper placement if condition==1, ///
		vertical lcolor(black) lwidth(medium) msize(zero)) (rcap lower2 upper2 placement if condition==1, vertical lcolor(black) lwidth(thick) msize(zero)) ///
		(scatter coef placement if condition==2, mcolor(blue) msize(large)) (rcap lower upper placement if condition==2, ///
		vertical lcolor(blue) lwidth(medium) msize(zero)) (rcap lower2 upper2 placement if condition==2, vertical lcolor(blue) lwidth(thick) msize(zero)), ///
		graphregion(margin(zero) fcolor(white) lcolor(white) lwidth(none) ifcolor(white) ilcolor(white)) subtitle(, color(black) nobox) title("") ///
		legend(order(3 "Unadjusted" 6 "Covariate adjusted") position(6) region(fcolor(white) lcolor(white)) size(large)) ///
		yscale(range(-.06 .16)) ylab(-.05(.05).15) xscale(range(0.5 2.5)) xlab(1 "High" 2 "Low", valuelabel nogrid labsize(large)) ///
		ylab(, nogrid labsize(medlarge)) yline(0, lcolor(black) lpattern(dash)) ///
		ytitle("Spillover effect on vote share", size(large)) xtitle("Municipal saturation", size(large)) xscale(titlegap(2)) yscale(titlegap(1)) bgcolor(white)
	graph export "Figures\indirect_effects_below_median_by_saturation.pdf", as(pdf) replace
	restore
}



*** Table 4: Effect of Facebook ads on precinct-level vote share for Lopez Obrador in the presidential election
quietly {
	preserve
	** Prepare data
	* Use federal legislative vote share in 2015 to proxy for lagged presidential vote share
	g pres_MOR_PT_PES_share_2015 = fed_MOR_PT_PES_share_2015
	g pres_MOR_PT_PES_reg_share_2015 = fed_MOR_PT_PES_reg_share_2015
	g pres_turnout_2015 = fed_turnout_2015
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg pres_MOR_PT_PES_share_2018 pres_MOR_PT_PES_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg pres_MOR_PT_PES_share_2018 pres_MOR_PT_PES_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	eststo clear
	* ATE, no interactive controls
	eststo, title("pres_MOR_PT_PES_share") : areg pres_MOR_PT_PES_share_2018 pres_MOR_PT_PES_share_2015 1.any_facebook_treatment 1.spillover ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum pres_MOR_PT_PES_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	* Facebook and spillover effects by median, no interactive controls
	eststo, title("pres_MOR_PT_PES_share") : areg pres_MOR_PT_PES_share_2018 pres_MOR_PT_PES_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum pres_MOR_PT_PES_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by median, interactive controls
	eststo, title("pres_MOR_PT_PES_share") : areg pres_MOR_PT_PES_share_2018 pres_MOR_PT_PES_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
		$any_facebook_treatment_controls $spillover_controls [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum pres_MOR_PT_PES_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_3a F_test_3b, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null ineffect below median ($ p$ value)" "Test: null ineffect above median ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover*) label varlabel(any_facebook_treatment "Facebook ads") ///
		drop(0.* *control* *0.above_malf_median) order(*any_facebook_treatment* *spillover*) 
	esttab est* using "Tables\full_table_pres_MOR_PT_PES_share_by_median.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_3a F_test_3b, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null ineffect below median ($ p$ value)" "Test: null ineffect above median ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover*) label varlabel(any_facebook_treatment "Facebook ads") ///
		drop(0.* *control* *0.above_malf_median) order(*any_facebook_treatment* *spillover*) replace	
	restore
}



*** Table 5: Differential effects of Facebook ads on precinct-level municipal incumbent party vote share, by Facebook's municipal-level social connectedness index
quietly {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	* Standardize SCI moderator
	sum sci_std_sample [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
	replace sci_std_sample = (sci_std_sample - `r(mean)')/`r(sd)'
	label var sci_std_sample "SCI (standardized)"
	** Regressions
	eststo clear
	* Facebook and spillover effects by saturation and median
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median##c.sci_std_sample ///
		[aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	* Facebook and spillover effects by saturation and median, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median##c.sci_std_sample $facebook_saturation_controls ///
		[aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome, fmt(%9.0fc %9.0fc 2 2 2 3 3 3 3 3) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev.")) starlevels(* .1 ** .05 *** .01) ///
		keep(*facebook_saturation*sci_std_sample) label varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" ///
		facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *0.above_malf_median*) ///
		order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) 
	esttab est* using "Tables\HEs_muni_inc_vote_share_by_median_by_sci_std_sample.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome, fmt(%9.0fc %9.0fc 2 2 2 3 3 3 3 3) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev.")) starlevels(* .1 ** .05 *** .01) ///
		keep(*facebook_saturation*sci_std_sample) label varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" ///
		facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *0.above_malf_median*) ///
		order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
	restore
}



*** Figure 6: Observed treatment effects within the distribution of placebo treatment assignments
preserve
** Estimate regression estimates from each of 5,000 alternative randomizations (randomization code is available upon request)
quietly forvalues k = 1/5000 {
	noisily di "ITERATION = `k'"
	use "Datasets\Permuted_Datasets\Main_Precinct_Dataset_`k'.dta", clear
	** Drop the block containing only 2 municipalities
	drop if block_size==2
	** Compute segment inverse weights to account for a segment's inverse probability of assignment to treatment
	* Weights that pool over CK
	g pooled_CK_prob = 1/3
	replace pooled_CK_prob = 1/3 * 4/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==3
	replace pooled_CK_prob = 1/3 * 1/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==3
	replace pooled_CK_prob = 1/3 * 1/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==2
	replace pooled_CK_prob = 1/3 * 4/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==2
	replace pooled_CK_prob = 1/2 * 1/3 if facebook_treatment==1 & saturation_treatment==2 & number_of_segments==3
	replace pooled_CK_prob = 1/2 * 2/3 if facebook_treatment==0 & saturation_treatment==2 & number_of_segments==3
	* Weights that pool over CK and saturation level
	g pooled_CK_sat_prob = 1/3
	replace pooled_CK_sat_prob = 2/3 * 1/2 if (facebook_treatment==1 | facebook_common_treatment==1) & (saturation_treatment==2 | saturation_treatment==3)
	replace pooled_CK_sat_prob = 2/3 * 1/2 if (facebook_treatment==0 & facebook_common_treatment==0) & (saturation_treatment==2 | saturation_treatment==3)
	replace pooled_CK_sat_prob = 1/2 * 1/3 if facebook_treatment==1 & number_of_segments==3
	replace pooled_CK_sat_prob = 1/2 * 2/3 if facebook_treatment==0 & number_of_segments==3
	* Population shares
	bysort code_INEGI segment : egen seg_listanominal_2018 = sum(muni_listanominal_2018)
	bysort code_INEGI : egen mun_listanominal_2018 = sum(muni_listanominal_2018)
	* Compute final weights for regressions
	g segment_pooled_CK_weight = muni_listanominal_2018/(pooled_CK_prob*seg_listanominal_2018)
	g segment_pooled_CK_sat_weight = muni_listanominal_2018/(pooled_CK_sat_prob*seg_listanominal_2018)
	g municipal_weight = muni_listanominal_2018 / ((1/block_size) * mun_listanominal_2018)
	* Define main treatment conditions
	g facebook_saturation = 0
	replace facebook_saturation = 1 if any_facebook_treatment==0 & saturation_treatment==2
	replace facebook_saturation = 2 if any_facebook_treatment==1 & saturation_treatment==2
	replace facebook_saturation = 3 if any_facebook_treatment==0 & saturation_treatment==3
	replace facebook_saturation = 4 if any_facebook_treatment==1 & saturation_treatment==3
	label define new_values 0 "Control" 1 "Indirect effect in low saturation" 2 "Direct effect in low saturation" 3 "Indirect effect in high saturation" 4 "Direct effect in high saturation"
	label values facebook_saturation new_values
	* Compute quartiles in the final sample
	sum share_irregularities_audited [aweight=municipal_weight], det
	g quartiles = 1
	replace quartiles = 3 if share_irreg>`r(p50)' & share_irreg<=`r(p75)'
	replace quartiles = 4 if share_irreg>`r(p75)'
	cap label define quartiles 1 "Q1/Q2" 3 "Q3" 4 "Q4"
	label values quartiles quartiles
	g above_malf_median = quartiles==3 | quartiles==4 if quartiles!=.
	cap label define median 0 "Q1 or Q2" 1 "Q3 or Q4"
	label values above_malf_median median
	** Prepare data: recompute segment weights in subsample
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	** Estimate heterogeneous effects by above/below malfeasance median (without covariate adjustment), and save coefficients
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	parmest, saving("Datasets\Permuted_Datasets\test_median_`k'.dta", replace)
	** Estimate heterogeneous effects by above/below malfeasance median by saturation (without covariate adjustment), and save coefficients
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	parmest, saving("Datasets\Permuted_Datasets\test_median_by_sat_`k'.dta", replace)
}
** Compute share of permuted datasets generating large effects than those observed: p-values for below-median malfeasance municipalities (without covariate adjustment)
quietly {
	clear all
	* Combine coefficients from all 5,000 regressions with permuted randomizations
	g iteration = .
	forvalues k = 1/5000 {
		append using "Datasets\Permuted_Datasets\test_median_`k'.dta"
		replace iteration = `k' if iteration==.
	}
	keep iteration parm estimate
	* Define the coefficients of interest observed with the actual randomization
	global FM0 = .0611879
	global FM1 = -.0851371
	global SM0 = .0265017
	global SM1 = -.0310551
	* Compute the share of more positive/more negative coefficients than we observe
	g RI_M_1 = estimate>$FM0 if parm=="1.any_facebook_treatment"
	g RI_M_2 = estimate<$FM1 if parm=="1.any_facebook_treatment#1.above_malf_median"
	g RI_M_3 = estimate>$SM0 if parm=="1.spillover"
	g RI_M_4 = estimate<$SM1 if parm=="1.spillover#1.above_malf_median"
	* (a) Direct effect in municipalities with below median irregularities
	sum RI_M_1
	local p = floor(`r(mean)'*1000 + 0.5) / 1000
	sum estimate if parm=="1.any_facebook_treatment", det
	global lower_end `r(min)'
	global upper_end `r(max)'
	twoway (kdensity estimate if parm=="1.any_facebook_treatment", range($lower_end $FM0) color(black)) ///
		(kdensity estimate if parm=="1.any_facebook_treatment", range($FM0 $upper_end) recast(area) color(gray)), ///
		legend(off) ylabel(, nogrid) ytitle("Density") xtitle("Placebo point estimate") text(2 0.09 "p = `p'")  ///
		subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
	graph export "Figures\direct_effect_below_median_RI.pdf", replace as(pdf)
	* (b) Indirect effect in municipalities with below median irregularities
	sum RI_M_3
	local p = floor(`r(mean)'*1000 + 0.5) / 1000
	sum estimate if parm=="1.spillover", det
	global lower_end `r(min)'
	global upper_end `r(max)'
	twoway (kdensity estimate if parm=="1.any_facebook_treatment", range($lower_end $SM0) color(black)) ///
		(kdensity estimate if parm=="1.any_facebook_treatment", range($SM0 $upper_end) recast(area) color(gray)), ///
		legend(off) ylabel(, nogrid) ytitle("Density") xtitle("Placebo point estimate") text(2 0.09 "p = `p'") ///
		subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
	graph export "Figures\indirect_effect_below_median_RI.pdf", replace as(pdf)
}
** Compute share of permuted datasets generating large effects than those observed: p-values for below-median malfeasance municipalities with high saturation (without covariate adjustment)
quietly {
	clear all
	* Combine coefficients from all 5,000 regressions with permuted randomizations
	g iteration = .
	forvalues k = 1/5000 {
		append using "Datasets\Permuted_Datasets\test_median_by_sat_`k'.dta"
		replace iteration = `k' if iteration==.
	}
	keep iteration parm estimate
	* Define the coefficients of interest observed with the actual randomization
	global FHM0 = .079177
	global FHM1 = -.1202998
	global FLM0 = .0216678
	global FLM1 = -.0240754
	global SHM0 = .0780745
	global SHM1 = -.1239537
	global SLM0 = .0086596
	global SLM1 = .0019296
	* Compute the share of more positive/more negative coefficients than we observe
	g RI_M_by_sat_1 = estimate>$FHM0 if parm=="4.facebook_saturation"
	g RI_M_by_sat_2 = estimate<$FHM1 if parm=="4.facebook_saturation#1.above_malf_median"
	g RI_M_by_sat_3 = estimate>$FLM0 if parm=="2.facebook_saturation"
	g RI_M_by_sat_4 = estimate<$FLM1 if parm=="2.facebook_saturation#1.above_malf_median"
	g RI_M_by_sat_5 = estimate>$SHM0 if parm=="3.facebook_saturation"
	g RI_M_by_sat_6 = estimate<$SHM1 if parm=="3.facebook_saturation#1.above_malf_median"
	g RI_M_by_sat_7 = estimate>$SLM0 if parm=="1.facebook_saturation"
	g RI_M_by_sat_8 = estimate<$SLM1 if parm=="1.facebook_saturation#1.above_malf_median"
	bysort iteration : g low_sat = estimate if parm=="2.facebook_saturation"
	bysort iteration : egen treated_low_sat = mean(low_sat)
	g treated_diff = estimate - treated_low_sat if parm=="4.facebook_saturation"
	g RI_treat_diff_by_sat = treated_diff>($FHM0-$FLM0) if parm=="4.facebook_saturation"
	drop low_sat treated_low_sat
	bysort iteration : g low_sat = estimate if parm=="1.facebook_saturation"
	bysort iteration : egen spill_low_sat = mean(low_sat)
	g spill_diff = estimate - spill_low_sat if parm=="3.facebook_saturation"
	g RI_spill_diff_by_sat = spill_diff>($SHM0-$SLM0) if parm=="3.facebook_saturation"
	drop low_sat spill_low_sat
	* (c) Direct effect in high saturation municipalities with below median irregularities
	sum RI_M_by_sat_1
	local p = floor(`r(mean)'*1000 + 0.5) / 1000
	sum estimate if parm=="4.facebook_saturation", det
	global lower_end `r(min)'
	global upper_end `r(max)'
	twoway (kdensity estimate if parm=="4.facebook_saturation", range($lower_end $FHM0) color(black)) ///
		(kdensity estimate if parm=="4.facebook_saturation", range($FHM0 $upper_end) recast(area) color(gray)), ///
		legend(off) ylabel(, nogrid) ytitle("Density") xtitle("Placebo point estimate") text(1 0.11 "p = `p'") ///
		subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
	graph export "Figures\direct_effect_below_median_H_RI.pdf", replace as(pdf)
	* (d) Indirect effect in high saturation municipalities with below median irregularities
	sum RI_M_by_sat_5
	local p = floor(`r(mean)'*1000 + 0.5) / 1000
	sum estimate if parm=="3.facebook_saturation", det
	global lower_end `r(min)'
	global upper_end `r(max)'
	twoway (kdensity estimate if parm=="3.facebook_saturation", range($lower_end $SHM0) color(black)) ///
		(kdensity estimate if parm=="3.facebook_saturation", range($SHM0 $upper_end) recast(area) color(gray)), ///
		legend(off) ylabel(, nogrid) ytitle("Density") xtitle("Placebo point estimate") text(1 0.11 "p = `p'") ///
		subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
	graph export "Figures\indirect_effect_below_median_H_RI.pdf", replace as(pdf)
	* (e) Difference in direct effect between high and low saturation municipalities with below median irregularities
	sum RI_treat_diff_by_sat
	local p = floor(`r(mean)'*1000 + 0.5) / 1000
	sum treated_diff, det
	global lower_end `r(min)'
	global upper_end `r(max)'
	local diff_treat = $FHM0-$FLM0
	twoway (kdensity treated_diff, range($lower_end `diff_treat') color(black)) ///
		(kdensity treated_diff, range(`diff_treat' $upper_end) recast(area) color(gray)), ///
		legend(off) ylabel(, nogrid) ytitle("Density") xtitle("Placebo point estimate") text(2 0.09 "p = `p'") ///
		subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
	graph export "Figures\differential_direct_effect_below_median_RI.pdf", replace as(pdf)
	* (f) Difference in indirect effect between high and low saturation municipalities with below median irregularities
	sum RI_spill_diff_by_sat
	local p = floor(`r(mean)'*1000 + 0.5) / 1000
	sum spill_diff, det
	global lower_end `r(min)'
	global upper_end `r(max)'
	local diff_spill = $FHM0-$FLM0
	twoway (kdensity spill_diff, range($lower_end `diff_spill') color(black)) ///
		(kdensity spill_diff, range(`diff_spill' $upper_end) recast(area) color(gray)), ///
		legend(off) ylabel(, nogrid) ytitle("Density") xtitle("Placebo point estimate") text(2 0.09 "p = `p'") ///
		subtitle(, color(black) fcolor(white) lcolor(white)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
	graph export "Figures\differential_indirect_effect_below_median_RI.pdf", replace as(pdf)
}
** Erase results files
quietly forvalues k = 1/5000 {
	erase "Datasets\Permuted_Datasets\test_median_`k'.dta"
	erase "Datasets\Permuted_Datasets\test_median_by_sat_`k'.dta"
}
restore





***************************** ONLINE APPENDIX

*** Table B.1: Municipality summary statistics
preserve
** Prepare data
quietly {
	use "Datasets\Main_Precinct_Dataset.dta", clear
	keep code_INEGI
	duplicates drop
	save "municipalities.dta", replace
	use "Datasets\Municipal_Level_Census_2015_Subset.dta", clear
	merge 1:1 code_INEGI using "municipalities.dta"
	g in_sample = (_merge==3 | code_INEGI==7064 | code_INEGI==12012)
	drop _merge
	erase "municipalities.dta"
	label var share_female_2015 "Share of population that are women"
	label var share_male_head_2015 "Share of households with a male head"
	label var pri_com_2015 "Share of population aged 15+ with at least complete primary schooling"
	label var sec_com_2015 "Population aged 15+ with at least complete secondary schooling"
	label var share_disabled_2015 "Share of population with a disability"
	label var share_economically_active_2015 "Share of population aged 12+ economically active"
	label var share_state_workers_health_2015 "Share of population with state worker's health care"
	label var mun_population_2015 "Population"
	** Make table
	eststo clear
	eststo, title("Experimental sample"): estpost summarize mun_population_2015 share_female_2015-ave_monthy_income_2015 if in_sample==1, listwise
	eststo, title("All other municipalities"): estpost summarize mun_population_2015 share_female_2015-ave_monthy_income_2015, listwise
	noisily esttab, cells("count(fmt(%9.0fc)) mean(fmt(2)) sd(fmt(2))") label nodepvar replace noobs nonumber nomtitle
	esttab * using "Tables\muni_summary_stats.tex", style(tex) cells("count(fmt(%9.0fc)) mean(fmt(2)) sd(fmt(2))") /// 
		prehead( ) posthead( ) prefoot() postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) noobs nonumbers label nodepvar nomtitle replace
}
restore



*** Table D.1: Engagement with Facebook ads in treated municipalities, by demographic subgroup
** Prepare and merge data
preserve
quietly {
	keep code_INEGI id_block saturation_treatment quartiles
	g above_malf_median = quartiles==3 | quartiles==4 if quartiles!=.
	cap label define median 0 "Below-median irregularities" 1 "Above-median irregularities"
	label values above_malf_median median
	duplicates drop
	merge 1:1 code_INEGI using "Datasets\ad_reach_characteristics.dta"
	drop if _merge==2
	drop _merge
	cap label define saturation_treatment_new 1 "Controls (pure + WhatsApp)" 2 "Low saturation" 3 "High saturation"
	label values saturation_treatment saturation_treatment_new
	quietly foreach x of varlist Alcancefemale-AlcanceNight Viewsfemale-ViewsNight {
		replace `x' = 0 if `x'==.
	}
}
** Run regressions and make tables
** Panel A: unique viewers
eststo clear
quietly foreach x of varlist Alcancefemale Alcance18_24-Alcance65above AlcanceMorning AlcanceAfternoon AlcanceEvening AlcanceNight Alcancesmartphone Alcancedesktop {
	eststo, title("`x'") : reg `x' i.saturation_treatment if saturation_treatment>1, ro
	sum `x' if e(sample) & saturation_treatment==2
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
}
estout, cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
	labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev.")) starlevels(* .1 ** .05 *** .01) keep(3.saturation_treatment) label 
esttab est* using "Tables\reach_by_type.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
	cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev.")) ///
	varlabel(3.saturation_treatment "High saturation") starlevels(* .1 ** .05 *** .01) keep(3.saturation_treatment) label replace
** Panel B: unique viewers, by above and below irregularities median
eststo clear
quietly foreach x of varlist Alcancefemale Alcance18_24-Alcance65above AlcanceMorning AlcanceAfternoon AlcanceEvening AlcanceNight Alcancesmartphone Alcancedesktop {
	eststo, title("`x'") : reg `x' i.saturation_treatment##above_malf_median if saturation_treatment>1, ro
	sum `x' if e(sample) & saturation_treatment==2
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
}
estout, cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
	labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev.")) starlevels(* .1 ** .05 *** .01) ///
	keep(1.above_malf_median 3.saturation_treatment*) order(1.above_malf_median 3.saturation_treatment*) drop(*0.above_malf_median) label 
esttab est* using "Tables\reach_by_type_median.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
	cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
	labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev.")) starlevels(* .1 ** .05 *** .01) ///
	keep(1.above_malf_median 3.saturation_treatment*) order(1.above_malf_median 3.saturation_treatment*) drop(*0.above_malf_median) label replace
** Panel C: views (of 3 seconds)
eststo clear
quietly foreach x of varlist Viewsfemale Views18_24-Views65above ViewsMorning ViewsAfternoon ViewsEvening ViewsNight Viewssmartphone Viewsdesktop {
	eststo, title("`x'") : reg `x' i.saturation_treatment if saturation_treatment>1, ro
	sum `x' if e(sample) & saturation_treatment==2
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
}
estout, cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
	labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev.")) starlevels(* .1 ** .05 *** .01) keep(3.saturation_treatment) label 
esttab est* using "Tables\reach_by_type_views.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
	cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev.")) ///
	varlabel(3.saturation_treatment "High saturation") starlevels(* .1 ** .05 *** .01) keep(3.saturation_treatment) label replace
** Panel D: views (of 3 seconds), by above and below irregularities median
eststo clear
quietly foreach x of varlist Viewsfemale Views18_24-Views65above ViewsMorning ViewsAfternoon ViewsEvening ViewsNight Viewssmartphone Viewsdesktop {
	eststo, title("`x'") : reg `x' i.saturation_treatment##above_malf_median if saturation_treatment>1, ro
	sum `x' if e(sample) & saturation_treatment==2
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
}
estout, cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
	labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev.")) starlevels(* .1 ** .05 *** .01) ///
	keep(1.above_malf_median 3.saturation_treatment*) order(1.above_malf_median 3.saturation_treatment*) drop(*0.above_malf_median) label 
esttab est* using "Tables\reach_by_type_views_median.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
	cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
	labels("Observations" "$ R^2$" "Low saturation outcome mean" "Low saturation outcome std. dev.")) starlevels(* .1 ** .05 *** .01) ///
	keep(1.above_malf_median 3.saturation_treatment*) order(1.above_malf_median 3.saturation_treatment*) drop(*0.above_malf_median) label replace
restore



*** Figure D.1: Trends in engagement with the Facebook ads during the information campaign
preserve
use "Datasets\Facebook_analytics_FS_Data", clear
** Prepare data
* Drop control municipalities
drop if saturation_treatment==1
* Remove label for Date for graphs
label var Date ""
** Make graphs
twoway  (scatter PaidImpressions Date if saturation_treatment==2, msymbol(diamond)) (scatter PaidImpressions Date if saturation_treatment==3), ///
	legend(lab(1 "Low saturation") lab(2 "High saturation") nobox region(color(white)) position(6) cols(2)) ///
	xtitle(" ") ytitle(Paid engagement with Facebook page content (unique users), angle(0) size(2.7)) ///
	graphregion(color(white) fcolor(white) lcolor(white)) bgcolor(white) xlab(, labsize(2.5) nogrid) ylab(, nogrid)
graph export "Figures\PaidImpressions.pdf", as(pdf) replace
twoway  (scatter PaidReach Date if saturation_treatment==2, msymbol(diamond)) (scatter PaidReach Date if saturation_treatment==3), ///
	legend(lab(1 "Low saturation") lab(2 "High saturation") nobox region(color(white)) position(6) cols(2)) ///
	xtitle(" ") ytitle(Paid accesing Facebook page content (unique users), angle(0) size(3)) ///
	graphregion(color(white) fcolor(white) lcolor(white)) bgcolor(white) xlab(, labsize(2.5) nogrid) ylab(, nogrid)
graph export "Figures\PaidReach.pdf", as(pdf) replace
twoway  (scatter TotalOrganicViews Date if saturation_treatment==2, msymbol(diamond)) (scatter TotalOrganicViews Date if saturation_treatment==3), ///
	legend(lab(1 "Low saturation") lab(2 "High saturation") nobox region(color(white)) position(6) cols(2)) ///
	xtitle(" ") ytitle(Social video views (total users), angle(0)) ///
	graphregion(color(white) fcolor(white) lcolor(white)) bgcolor(white) xlab(, labsize(2.5) nogrid) ylab(, nogrid)
graph export "Figures\TotalOrganicViews(not unique).pdf", as(pdf) replace
twoway  (scatter OrganicReach Date if saturation_treatment==2, msymbol(diamond)) (scatter OrganicReach Date if saturation_treatment==3), ///
	legend(lab(1 "Low saturation") lab(2 "High saturation") nobox region(color(white)) position(6) cols(2)) ///
	xtitle(" ") ytitle(Social accesing Facebook page content (unique users), angle(0) size(3)) ///
	graphregion(color(white) fcolor(white) lcolor(white)) bgcolor(white) xlab(, labsize(2.5) nogrid) ylab(, nogrid)
graph export "Figures\OrganicReach.pdf", as(pdf) replace
twoway  (scatter TotalUniqueVideoViews Date if saturation_treatment==2, msymbol(diamond)) (scatter TotalUniqueVideoViews Date if saturation_treatment==3), ///
	legend(lab(1 "Low saturation") lab(2 "High saturation") nobox region(color(white)) position(6) cols(2)) ///
	xtitle(" ") ytitle(Video views (unique users), angle(0)) ///
	graphregion(color(white) fcolor(white) lcolor(white)) bgcolor(white) xlab(, labsize(2.5) nogrid) ylab(, nogrid)
graph export "Figures\TotalUniqueVideoViews.pdf", as(pdf) replace
twoway  (scatter TotalUnique30Second Date if saturation_treatment==2, msymbol(diamond)) (scatter TotalUnique30Second Date if saturation_treatment==3), ///
	legend(lab(1 "Low saturation") lab(2 "High saturation") nobox region(color(white)) position(6) cols(2)) ///
	xtitle(" ") ytitle(30-second video views (unique users), angle(0)) ///
	graphregion(color(white) fcolor(white) lcolor(white)) bgcolor(white) xlab(, labsize(2.5) nogrid) ylab(, nogrid)
graph export "Figures\TotalUnique30SecondV.pdf", as(pdf) replace
restore



*** Figure D.2: Distribution of engagement with the Facebook ads during the information campaign, by municipal saturation
preserve
quietly {
	use "Datasets\facebook_ads.dta", clear
	duplicates drop code_INEGI, force
	** Make figures
	foreach x of varlist PaidImpressions PaidReach Organicimpressions OrganicReach TotalUniqueVideoViews TotalUnique30SecondV {
		replace `x' = 0 if `x'==.
		sum `x', det
		local min = `r(max)'
		local max = `r(max)'
		local width = `max'/20
		twoway (hist `x' if saturation_treatment==2, width(`width') frac lcolor(blue) fcolor(none)) (hist `x' if saturation_treatment==3, width(`width') frac fcolor(none) lcolor(black)), ///
			legend(region(color(white) margin(none)) size(large) label(1 "Low saturation") label(2 "High saturation") position(6)) subtitle(, color(black) nobox) /// 
			graphregion(margin(zero) fcolor(white) lcolor(yellow) lwidth(none) ifcolor(white) ilcolor(white)) title("") ///
			xscale(range(`min' `max')) ylab(, nogrid labsize(large)) xlab(, labsize(large)) ytitle("Density", size(large)) xtitle("Municipal count per capita", size(large)) 
		graph export "Figures\histogram_`x'_both.pdf", as(pdf) replace
	}
}
restore



*** Table E.1: Effect of Facebook ads on precinct-level municipal incumbent party vote share, including the block containing only two municipalities
quietly {
	preserve
	** Clean dataset without dropping rump block
	use "Datasets\Main_Precinct_Dataset.dta", clear
	g full_prob = 1/3
	replace full_prob = 1/3 * 2/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==3
	replace full_prob = 1/3 * 1/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==3
	replace full_prob = 1/3 * 1/10 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==2
	replace full_prob = 1/3 * 4/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==2
	replace full_prob = 1/2 * 1/6 if facebook_treatment==1 & saturation_treatment==2 & number_of_segments==3
	replace full_prob = 1/2 * 2/3 if facebook_treatment==0 & saturation_treatment==2 & number_of_segments==3
	g pooled_CK_prob = 1/3
	replace pooled_CK_prob = 1/3 * 4/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==3
	replace pooled_CK_prob = 1/3 * 1/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==3
	replace pooled_CK_prob = 1/3 * 1/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==2
	replace pooled_CK_prob = 1/3 * 4/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==2
	replace pooled_CK_prob = 1/2 * 1/3 if facebook_treatment==1 & saturation_treatment==2 & number_of_segments==3
	replace pooled_CK_prob = 1/2 * 2/3 if facebook_treatment==0 & saturation_treatment==2 & number_of_segments==3
	g pooled_sat_prob = 1/3
	replace pooled_sat_prob = 2/3 * 1/4 if (facebook_treatment==1 | facebook_common_treatment==1) & (saturation_treatment==2 | saturation_treatment==3)
	replace pooled_sat_prob = 2/3 * 1/2 if (facebook_treatment==0 & facebook_common_treatment==0) & (saturation_treatment==2 | saturation_treatment==3)
	replace pooled_sat_prob = 1/2 * 1/6 if facebook_treatment==1 & number_of_segments==3
	replace pooled_sat_prob = 1/2 * 2/3 if facebook_treatment==0 & number_of_segments==3
	g pooled_CK_sat_prob = 1/3
	replace pooled_CK_sat_prob = 2/3 * 1/2 if (facebook_treatment==1 | facebook_common_treatment==1) & (saturation_treatment==2 | saturation_treatment==3)
	replace pooled_CK_sat_prob = 2/3 * 1/2 if (facebook_treatment==0 & facebook_common_treatment==0) & (saturation_treatment==2 | saturation_treatment==3)
	replace pooled_CK_sat_prob = 1/2 * 1/3 if facebook_treatment==1 & number_of_segments==3
	replace pooled_CK_sat_prob = 1/2 * 2/3 if facebook_treatment==0 & number_of_segments==3
	bysort code_INEGI segment : egen replacement = sum(p_18ymas)
	replace seg_p_18ymas = replacement
	drop replacement mun_p_18ymas
	bysort code_INEGI : egen mun_p_18ymas = sum(p_18ymas)
	bysort code_INEGI segment : egen seg_listanominal_2018 = sum(muni_listanominal_2018)
	bysort code_INEGI : egen mun_listanominal_2018 = sum(muni_listanominal_2018)
	g segment_full_weight = muni_listanominal_2018/(full_prob*seg_listanominal_2018)
	g segment_pooled_CK_weight = muni_listanominal_2018/(pooled_CK_prob*seg_listanominal_2018)
	g segment_pooled_sat_weight = muni_listanominal_2018/(pooled_sat_prob*seg_listanominal_2018)
	g segment_pooled_CK_sat_weight = muni_listanominal_2018/(pooled_CK_sat_prob*seg_listanominal_2018)
	g segment_weight = muni_listanominal_2018/((1/block_size)*seg_listanominal_2018)
	g municipal_weight = muni_listanominal_2018/((1/block_size)*mun_listanominal_2018)
	g any_facebook_treatment = facebook_treatment==1 | facebook_common_treatment==1
	label define d_new_values 0 "Control" 1 "Direct effect"
	label values any_facebook_treatment d_new_values
	g any_saturation_treatment = saturation_treatment!=1
	label define any_saturation_treatment 0 "Control" 1 "Any Saturation"
	label values any_saturation_treatment any_saturation_treatment
	g spillover = saturation_treatment!=1 & any_facebook_treatment==0
	label define i_new_values 0 "Control" 1 "Indirect effect"
	label values spillover i_new_values
	g facebook_saturation = 0
	replace facebook_saturation = 1 if any_facebook_treatment==0 & saturation_treatment==2
	replace facebook_saturation = 2 if any_facebook_treatment==1 & saturation_treatment==2
	replace facebook_saturation = 3 if any_facebook_treatment==0 & saturation_treatment==3
	replace facebook_saturation = 4 if any_facebook_treatment==1 & saturation_treatment==3
	label define new_values 0 "Control" 1 "Indirect effect in low saturation" 2 "Direct effect in low saturation" 3 "Indirect effect in high saturation" 4 "Direct effect in high saturation"
	label values facebook_saturation new_values
	sum share_irregularities_audited [aweight=municipal_weight], det
	g quartiles = 1
	replace quartiles = 3 if share_irreg>`r(p50)' & share_irreg<=`r(p75)'
	replace quartiles = 4 if share_irreg>`r(p75)'
	cap label define quartile 1 "Irregularities Q1/Q2" 3 "Irregularities Q3" 4 "Irregularities Q4"
	label values quartiles quartile
	g above_malf_median = quartiles==3 | quartiles==4 if quartiles!=.
	cap label define median 0 "Below-median irregularities" 1 "Above-median irregularities"
	label values above_malf_median median
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	eststo clear
	* ATE, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 1.any_facebook_treatment 1.spillover [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	* Facebook and spillover effects by median, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by median, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by quartile, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	* Facebook and spillover effects by quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	restore
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* Facebook and spillover effects by saturation
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_1 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_2 = `r(p)'
	* Facebook and spillover effects by saturation and quartile
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and quartile
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	restore
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) 	
	esttab est* using "Tables\full_table_muni_inc_vote_share_added_rump_block.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
}



*** Table F.1: Municipal-level Facebook saturation treatment condition balance tests
quietly {
	preserve
	* Merge in 2015 municipal census data
	merge m:1 code_INEGI using "Datasets\Municipal_Level_Census_2015_Subset.dta"
	drop if _merge==2
	drop _merge
	* Recompute municipal weights in subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.saturation_treatment [aweight=municipal_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI : egen replacement = sum(muni_listanominal_2018)
	replace municipal_weight = muni_listanominal_2018 / ((1/block_size) * replacement)
	* Run balance tests
	eststo clear
	foreach x of varlist Audit_Year-Auditados share_irregularities_audited mun_p_18ymas muni_listanominal_2015 muni_incumbent_candidate muni_inc_vote_share_2015 muni_turnout_2015 ///
			fed_MOR_PT_PES_share_2015 fed_PAN_PRD_MC_share_2015 fed_PRI_PVEM_NA_share_2015 fed_turnout_2015 share_female_2015-share_internet_2015 {
		eststo, title("`x'") : areg `x' i.saturation_treatment [aweight=municipal_weight], cluster(code_INEGI) a(id_block)
		sum `x' [aweight=municipal_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 2.saturation_treatment = 3.saturation_treatment = 0
		estadd scalar F_test = `r(p)'
	}
	noisily estout, cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome SD_Outcome F_test, fmt(%9.0fc 2 2 2) labels("Observations" "Control mean" ///
		"Control std. dev." "F test of all coefficients = 0")) starlevels(* .1 ** .05 *** .01) keep(2.saturation_treatment 3.saturation_treatment) label 
	estout * using "Tables\Municipal balance.txt", cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome SD_Outcome F_test, fmt(%9.0fc 2 2 2) labels("Observations" "Control mean" ///
		"Control std. dev." "F test of all coefficients = 0")) starlevels(* .1 ** .05 *** .01) keep(2.saturation_treatment 3.saturation_treatment) label replace
	restore
}



*** Table F.2: Segment-level Facebook ad treatment condition balance tests
quietly {
	preserve
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Run balance tests
	eststo clear
	foreach x of varlist Audit_Year-Auditados share_irregularities_audited mun_p_18ymas seg_p_18ymas p_18ymas ///
			muni_listanominal_2015 muni_incumbent_candidate muni_inc_vote_share_2015 muni_turnout_2015 ///
			fed_MOR_PT_PES_share_2015 fed_PAN_PRD_MC_share_2015 fed_PRI_PVEM_NA_share_2015 fed_turnout_2015 census_households-share_internet {
		eststo, title("`x'") : areg `x' i.facebook_saturation [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x' [aweight=segment_pooled_CK_weight] if e(sample) & facebook_saturation==0
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 1.facebook_saturation = 2.facebook_saturation = 3.facebook_saturation = 4.facebook_saturation = 0
		estadd scalar F_test = `r(p)'
	}
	noisily estout, cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome SD_Outcome F_test, fmt(%9.0fc 2 2 2) labels("Observations" "Control mean" "Control std. dev." ///
		"F test of all coefficients = 0")) starlevels(* .1 ** .05 *** .01) keep(*.facebook_saturation) drop(0.facebook_saturation) label 
	estout * using "Tables\Precinct balance.txt", cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome SD_Outcome F_test, fmt(%9.0fc 2 2 2) labels("Observations" "Control mean" "Control std. dev." ///
		"F test of all coefficients = 0")) starlevels(* .1 ** .05 *** .01) keep(*.facebook_saturation) drop(0.facebook_saturation) label replace
	restore
}



*** Table F.3: Segment-level Facebook ad treatment condition balance tests, above and below the median of the municipal irregularities distribution
quietly {
	preserve
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Run balance tests
	eststo clear
	foreach x of varlist Audit_Year-Auditados share_irregularities_audited mun_p_18ymas seg_p_18ymas p_18ymas ///
			muni_listanominal_2015 muni_incumbent_candidate muni_turnout_2015 ///
			fed_MOR_PT_PES_share_2015 fed_PAN_PRD_MC_share_2015 fed_PRI_PVEM_NA_share_2015 fed_turnout_2015 census_households-share_internet {
		eststo, title("`x'") : areg `x' muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x' [aweight=segment_pooled_CK_weight] if e(sample) & facebook_saturation==0
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 1.facebook_saturation = 2.facebook_saturation = 3.facebook_saturation = 4.facebook_saturation = 0
		estadd scalar F_test_1 = `r(p)'
		test 1.facebook_saturation + 1.facebook_saturation#1.above_malf_median = 2.facebook_saturation + 2.facebook_saturation#1.above_malf_median = ///
			3.facebook_saturation + 3.facebook_saturation#1.above_malf_median = 4.facebook_saturation + 4.facebook_saturation#1.above_malf_median = 0
		estadd scalar F_test_2 = `r(p)'
		test 1.facebook_saturation = 2.facebook_saturation = 3.facebook_saturation = 4.facebook_saturation = ///
			1.facebook_saturation + 1.facebook_saturation#1.above_malf_median = 2.facebook_saturation + 2.facebook_saturation#1.above_malf_median = ///
			3.facebook_saturation + 3.facebook_saturation#1.above_malf_median = 4.facebook_saturation + 4.facebook_saturation#1.above_malf_median = 0
		estadd scalar F_test_3 = `r(p)'
	}
	noisily estout, cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome SD_Outcome F_test_1 F_test_2 F_test_3, fmt(%9.0fc 2 2 2 2 2) ///
		labels("Observations" "Control mean" "Control std. dev." "F test of all coefficients below median = 0" "F test of all coefficients above median = 0" ///
		"F test of all coefficients below and above median = 0")) ///
		starlevels(* .1 ** .05 *** .01) keep(*.facebook_saturation) drop(0.facebook_saturation) label 
	estout * using "Tables\Precinct balance_by_median.txt", cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome SD_Outcome F_test_1 F_test_2 F_test_3, fmt(%9.0fc 2 2 2 2 2) ///
		labels("Observations" "Control mean" "Control std. dev." "F test of all coefficients below median = 0" "F test of all coefficients above median = 0" ///
		"F test of all coefficients below and above median = 0")) ///
		starlevels(* .1 ** .05 *** .01) keep(*.facebook_saturation) drop(0.facebook_saturation) label replace
	restore
}



*** Table F.4: Segment-level Facebook ad treatment condition balance tests, by quartile of the municipal irregularities distribution
quietly {
	preserve
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Run balance tests
	eststo clear
	foreach x of varlist Audit_Year-Auditados share_irregularities_audited mun_p_18ymas seg_p_18ymas p_18ymas ///
			muni_listanominal_2015 muni_incumbent_candidate muni_turnout_2015 ///
			fed_MOR_PT_PES_share_2015 fed_PAN_PRD_MC_share_2015 fed_PRI_PVEM_NA_share_2015 fed_turnout_2015 census_households-share_internet {
		eststo, title("`x'") : areg `x' muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x' [aweight=segment_pooled_CK_weight] if e(sample) & facebook_saturation==0
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 1.facebook_saturation = 2.facebook_saturation = 3.facebook_saturation = 4.facebook_saturation = 0
		estadd scalar F_test_1 = `r(p)'
		test 1.facebook_saturation + 1.facebook_saturation#3.quartiles = 2.facebook_saturation + 2.facebook_saturation#3.quartiles = ///
			3.facebook_saturation + 3.facebook_saturation#3.quartiles = 4.facebook_saturation + 4.facebook_saturation#3.quartiles = 0
		estadd scalar F_test_3 = `r(p)'
		test 1.facebook_saturation + 1.facebook_saturation#4.quartiles = 2.facebook_saturation + 2.facebook_saturation#4.quartiles = ///
			3.facebook_saturation + 3.facebook_saturation#4.quartiles = 4.facebook_saturation + 4.facebook_saturation#4.quartiles = 0
		estadd scalar F_test_4 = `r(p)'
		test 1.facebook_saturation = 2.facebook_saturation = 3.facebook_saturation = 4.facebook_saturation = ///
			1.facebook_saturation + 1.facebook_saturation#3.quartiles = 2.facebook_saturation + 2.facebook_saturation#3.quartiles = ///
			3.facebook_saturation + 3.facebook_saturation#3.quartiles = 4.facebook_saturation + 4.facebook_saturation#3.quartiles = ///
			1.facebook_saturation + 1.facebook_saturation#4.quartiles = 2.facebook_saturation + 2.facebook_saturation#4.quartiles = ///
			3.facebook_saturation + 3.facebook_saturation#4.quartiles = 4.facebook_saturation + 4.facebook_saturation#4.quartiles = 0
		estadd scalar F_test_5 = `r(p)'
	}
	noisily estout, cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome SD_Outcome F_test_1 F_test_3 F_test_4 F_test_5, fmt(%9.0fc 2 2 2) ///
		labels("Observations" "Control mean" "Control std. dev." "F test of all coefficients in Q1/Q2 = 0" "F test of all coefficients in Q3 = 0" ///
		"F test of all coefficients in Q4 = 0" "F test of all coefficients in all quartiles = 0")) ///
		starlevels(* .1 ** .05 *** .01) keep(*.facebook_saturation) drop(0.facebook_saturation) label
	estout * using "Tables\Precinct balance_by_quartile.txt", cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome SD_Outcome F_test_1 F_test_3 F_test_4 F_test_5, fmt(%9.0fc 2 2 2) ///
		labels("Observations" "Control mean" "Control std. dev." "F test of all coefficients in Q1/Q2 = 0" "F test of all coefficients in Q3 = 0" ///
		"F test of all coefficients in Q4 = 0" "F test of all coefficients in all quartiles = 0")) ///
		starlevels(* .1 ** .05 *** .01) keep(*.facebook_saturation) drop(0.facebook_saturation) label replace
	restore
}



*** Table F.5: Covariate summary statistics, by irregularities quartile
quietly {
	preserve
	* Merge in 2015 municipal census data
	merge m:1 code_INEGI using "Datasets\Municipal_Level_Census_2015_Subset.dta"
	drop if _merge==2
	drop _merge
	* Recompute municipal weights in subsample
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.saturation_treatment [aweight=municipal_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI : egen replacement = sum(muni_listanominal_2018)
	replace municipal_weight = muni_listanominal_2018 / ((1/block_size) * replacement)
	* Run balance tests
	eststo clear
	foreach x of varlist Audit_Year-Auditados share_irregularities_audited mun_p_18ymas muni_listanominal_2015 muni_incumbent_candidate muni_inc_vote_share_2015 muni_turnout_2015 ///
			fed_MOR_PT_PES_share_2015 fed_PAN_PRD_MC_share_2015 fed_PRI_PVEM_NA_share_2015 fed_turnout_2015 share_female_2015-share_internet_2015 {
		eststo, title("`x'") : areg `x' i.quartiles [aweight=municipal_weight], cluster(code_INEGI) a(id_block)
		foreach n of numlist 1 3 4 {
			sum `x' [aweight=municipal_weight] if e(sample) & quartiles==`n'
			estadd scalar Mean_Outcome_Q`n' = `r(mean)'
			estadd scalar SD_Outcome_Q`n' = `r(sd)'
		}
		test 1.quartiles = 3.quartiles = 4.quartiles = 0
		estadd scalar F_test = `r(p)'
	}
	noisily estout, cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome_Q1 SD_Outcome_Q1 Mean_Outcome_Q3 SD_Outcome_Q3 Mean_Outcome_Q4 SD_Outcome_Q4 F_test, ///
		fmt(%9.0fc 2 2 2 2 2 2 2) labels("Observations" "Q1/Q2 mean" "Q1/Q2 std. dev." "Q3 mean" "Q3 std. dev." "Q4 mean" "Q4 std. dev." "F test of equality across quartiles")) ///
		starlevels(* .1 ** .05 *** .01) keep(*.quartiles) drop(1.quartiles) label
	estout * using "Tables\Quartiles balance.txt", cells(b(star fmt(2)) se(par)) stats(N Mean_Outcome_Q1 SD_Outcome_Q1 Mean_Outcome_Q3 SD_Outcome_Q3 Mean_Outcome_Q4 SD_Outcome_Q4 F_test, ///
		fmt(%9.0fc 2 2 2 2 2 2 2) labels("Observations" "Q1/Q2 mean" "Q1/Q2 std. dev." "Q3 mean" "Q3 std. dev." "Q4 mean" "Q4 std. dev." "F test of equality across quartiles")) ///
		starlevels(* .1 ** .05 *** .01) keep(*.quartiles) drop(1.quartiles) label replace
	restore
}



*** Table G.1: Effects of municipal saturation treatments on municipal election outcomes
quietly {
	preserve
	duplicates drop code_INEGI, force
	eststo clear
	eststo, title("muni_incumbent_win") : areg muni_incumbent_win_2018 1.any_saturation_treatment, ro a(id_block)
	sum muni_incumbent_win_2018 if e(sample) & any_saturation_treatment==0
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	eststo, title("muni_incumbent_win") : areg muni_incumbent_win_2018 any_saturation_treatment##above_malf_median, ro a(id_block)
	sum muni_incumbent_win_2018 if e(sample) & any_saturation_treatment==0
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_saturation_treatment = 0
	estadd scalar F_test_Q1 = `r(p)'
	test 1.any_saturation_treatment + 1.any_saturation_treatment#1.above_malf_median = 0
	estadd scalar F_test_above = `r(p)'
	eststo, title("muni_incumbent_win") : areg muni_incumbent_win_2018 any_saturation_treatment##quartiles, ro a(id_block)
	sum muni_incumbent_win_2018 if e(sample) & any_saturation_treatment==0
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_saturation_treatment = 0
	estadd scalar F_test_Q1 = `r(p)'
	test 1.any_saturation_treatment + 1.any_saturation_treatment#3.quartiles = 0
	estadd scalar F_test_Q3 = `r(p)'
	test 1.any_saturation_treatment + 1.any_saturation_treatment#4.quartiles = 0
	estadd scalar F_test_Q4 = `r(p)'
	eststo, title("muni_incumbent_win") : areg muni_incumbent_win_2018 i.saturation_treatment, ro a(id_block)
	sum muni_incumbent_win_2018 if e(sample) & any_saturation_treatment==0
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 2.saturation_treatment == 3.saturation_treatment
	estadd scalar F_test = `r(p)'
	eststo, title("muni_incumbent_win") : areg muni_incumbent_win_2018 i.saturation_treatment##above_malf_median, ro a(id_block)
	sum muni_incumbent_win_2018 if e(sample) & any_saturation_treatment==0
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 2.saturation_treatment = 0
	estadd scalar F_test_below_1 = `r(p)'
	test 2.saturation_treatment + 2.saturation_treatment#1.above_malf_median = 0
	estadd scalar F_test_above_1 = `r(p)'
	test 3.saturation_treatment = 0
	estadd scalar F_test_below_2 = `r(p)'
	test 3.saturation_treatment + 3.saturation_treatment#1.above_malf_median = 0
	estadd scalar F_test_above_2 = `r(p)'
	eststo, title("muni_incumbent_win") : areg muni_incumbent_win_2018 i.saturation_treatment##quartiles, ro a(id_block)
	sum muni_incumbent_win_2018 if e(sample) & any_saturation_treatment==0
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 2.saturation_treatment = 0
	estadd scalar F_test_below_1 = `r(p)'
	test 2.saturation_treatment + 2.saturation_treatment#3.quartiles = 0
	estadd scalar F_test_Q3_1 = `r(p)'
	test 2.saturation_treatment + 2.saturation_treatment#4.quartiles = 0
	estadd scalar F_test_Q4_1 = `r(p)'
	test 3.saturation_treatment = 0
	estadd scalar F_test_below_2 = `r(p)'
	test 3.saturation_treatment + 3.saturation_treatment#3.quartiles = 0
	estadd scalar F_test_Q3_2 = `r(p)'
	test 3.saturation_treatment + 3.saturation_treatment#4.quartiles = 0
	estadd scalar F_test_Q4_2 = `r(p)'
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome F_test_Q1 F_test_above F_test_Q3 F_test_Q4 ///
		F_test F_test_below_1 F_test_above_1 F_test_below_2 F_test_above_2 F_test_Q3_1 F_test_Q4_1 F_test_Q3_2 F_test_Q4_2, fmt(%9.0fc 2 2 2) ///
		labels("Observations" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: effect of treatment below median ($ p$ value, 2-sided)" "Test: effect of treatment above median ($ p$ value, 2-sided)" ///
		"Test: effect of treatment in Q3 ($ p$ value, 2-sided)" "Test: effect of treatment in Q4 ($ p$ value, 2-sided)" ///
		"Test: low = high ($ p$ value, 2-sided)" "Test: effect of low saturation below median ($ p$ value, 2-sided)" "Test: effect of low saturation above median ($ p$ value, 2-sided)" ///
		"Test: effect of high saturation below median ($ p$ value, 2-sided)" "Test: effect of high saturation above median ($ p$ value, 2-sided)" ///
		"Test: effect of low saturation in Q3 ($ p$ value, 2-sided)" "Test: effect of low saturation in Q4 ($ p$ value, 2-sided)" ///
		"Test: effect of high saturation in Q3 ($ p$ value, 2-sided)" "Test: effect of high saturation in Q4 ($ p$ value, 2-sided)" )) starlevels(* .1 ** .05 *** .01) ///
		keep(1.any_saturation_treatment* 2.saturation_treatment* 3.saturation_treatment*) drop(*1.quartiles* *0.above_malf_median) ///
		order(1.any_saturation_treatment* 3.saturation_treatment* 2.saturation_treatment*) label
	esttab est* using "Tables\muni_ATEs_muni_incumbent_win.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome F_test_Q1 F_test_above F_test_Q3 F_test_Q4 ///
		F_test F_test_below_1 F_test_above_1 F_test_below_2 F_test_above_2 F_test_Q3_1 F_test_Q4_1 F_test_Q3_2 F_test_Q4_2, fmt(%9.0fc 2 2 2) ///
		labels("Observations" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: effect of treatment below median ($ p$ value, 2-sided)" "Test: effect of treatment above median ($ p$ value, 2-sided)" ///
		"Test: effect of treatment in Q3 ($ p$ value, 2-sided)" "Test: effect of treatment in Q4 ($ p$ value, 2-sided)" ///
		"Test: low = high ($ p$ value, 2-sided)" "Test: effect of low saturation below median ($ p$ value, 2-sided)" "Test: effect of low saturation above median ($ p$ value, 2-sided)" ///
		"Test: effect of high saturation below median ($ p$ value, 2-sided)" "Test: effect of high saturation above median ($ p$ value, 2-sided)" ///
		"Test: effect of low saturation in Q3 ($ p$ value, 2-sided)" "Test: effect of low saturation in Q4 ($ p$ value, 2-sided)" ///
		"Test: effect of high saturation in Q3 ($ p$ value, 2-sided)" "Test: effect of high saturation in Q4 ($ p$ value, 2-sided)" )) starlevels(* .1 ** .05 *** .01) ///
		keep(1.any_saturation_treatment* 2.saturation_treatment* 3.saturation_treatment*) drop(*1.quartiles* *0.above_malf_median) ///
		order(1.any_saturation_treatment* 3.saturation_treatment* 2.saturation_treatment*) label replace
	restore
}



*** Table G.2: Effect of Facebook ads on precinct-level vote share in nearby municipalities
quietly {
	preserve
	use "Datasets\Spillover_Dataset.dta", clear
	** Clean dataset
	* Compute segment-level weights to account for a segment's inverse probability of assignment to treatment
	g pooled_CK_prob = 1/3
	replace pooled_CK_prob = 1/3 * 4/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==3
	replace pooled_CK_prob = 1/3 * 1/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==3
	replace pooled_CK_prob = 1/3 * 1/5 if (facebook_treatment==1 | facebook_common_treatment==1) & saturation_treatment==2
	replace pooled_CK_prob = 1/3 * 4/5 if (facebook_treatment==0 & facebook_common_treatment==0) & saturation_treatment==2
	replace pooled_CK_prob = 1/2 * 1/3 if facebook_treatment==1 & saturation_treatment==2 & number_of_segments==3
	replace pooled_CK_prob = 1/2 * 2/3 if facebook_treatment==0 & saturation_treatment==2 & number_of_segments==3
	g pooled_CK_sat_prob = 1/3
	replace pooled_CK_sat_prob = 2/3 * 1/2 if (facebook_treatment==1 | facebook_common_treatment==1) & (saturation_treatment==2 | saturation_treatment==3)
	replace pooled_CK_sat_prob = 2/3 * 1/2 if (facebook_treatment==0 & facebook_common_treatment==0) & (saturation_treatment==2 | saturation_treatment==3)
	replace pooled_CK_sat_prob = 1/2 * 1/3 if facebook_treatment==1 & number_of_segments==3
	replace pooled_CK_sat_prob = 1/2 * 2/3 if facebook_treatment==0 & number_of_segments==3
	bysort code_INEGI segment : egen seg_listanominal_2018 = sum(muni_listanominal_2018)
	bysort code_INEGI : egen mun_listanominal_2018 = sum(muni_listanominal_2018)
	g segment_pooled_CK_weight = muni_listanominal_2018/(pooled_CK_prob*seg_listanominal_2018)
	g segment_pooled_CK_sat_weight = muni_listanominal_2018/(pooled_CK_sat_prob*seg_listanominal_2018)
	* Compute quartiles in the final sample (block drop occurs at the beginning of this section)
	cap label define quartile 1 "Irregularities Q1/Q2" 3 "Irregularities Q3" 4 "Irregularities Q4"
	label values quartiles quartile
	g above_malf_median = quartiles==3 | quartiles==4 if quartiles!=.
	cap label define median 0 "Below-median irregularities" 1 "Above-median irregularities"
	label values above_malf_median median
	* Label treatments
	g any_facebook_treatment = facebook_treatment==1 | facebook_common_treatment==1
	label define d_new_values 0 "Control" 1 "Direct effect"
	label values any_facebook_treatment d_new_values
	g any_saturation_treatment = saturation_treatment!=1
	label define any_saturation_treatment 0 "Control" 1 "Any Saturation"
	label values any_saturation_treatment any_saturation_treatment
	g spillover = saturation_treatment!=1 & any_facebook_treatment==0
	label define i_new_values 0 "Control" 1 "Indirect effect"
	label values spillover i_new_values
	g facebook_saturation = 0
	replace facebook_saturation = 1 if any_facebook_treatment==0 & saturation_treatment==2
	replace facebook_saturation = 2 if any_facebook_treatment==1 & saturation_treatment==2
	replace facebook_saturation = 3 if any_facebook_treatment==0 & saturation_treatment==3
	replace facebook_saturation = 4 if any_facebook_treatment==1 & saturation_treatment==3
	label define new_values 0 "Control" 1 "Indirect effect in low saturation" 2 "Direct effect in low saturation" 3 "Indirect effect in high saturation" 4 "Direct effect in high saturation"
	label values facebook_saturation new_values
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	reg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	** Regressions
	eststo clear
	* ATE, no interactive controls
	eststo, title("muni_inc_vote_share") : reg muni_inc_vote_share_2018 muni_inc_vote_share_2015 1.any_facebook_treatment 1.spillover [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	* Facebook and spillover effects by median, no interactive controls
	eststo, title("muni_inc_vote_share") : reg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by median, interactive controls
	eststo, title("muni_inc_vote_share") : reg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by quartile, no interactive controls
	eststo, title("muni_inc_vote_share") : reg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1 = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_2 = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3 = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by quartile, interactive controls
	eststo, title("muni_inc_vote_share") : reg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1 = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_2 = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3 = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_4 = `r(p)'
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1 F_test_2 F_test_3a F_test_3b F_test_3 F_test_4, ///
		fmt(%9.0fc %9.0fc 2 2 2) labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" facebook_treatment ///
		"Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) order(*any_facebook_treatment* *spillover*)
	esttab est* using "Tables\neighbor_spillover_muni_inc_vote_share.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1 F_test_2 F_test_3a F_test_3b F_test_3 F_test_4, ///
		fmt(%9.0fc %9.0fc 2 2 2) labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" facebook_treatment ///
		"Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) order(*any_facebook_treatment* *spillover*) replace
	restore
}



*** Table H.1: Effect of Facebook ads on precinct-level municipal incumbent party vote share and electoral turnout, by quartile of the irregularities distribution
eststo clear
quietly foreach x in muni_inc_vote_share muni_turnout {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* Facebook and spillover effects by quartile, no interactive controls
	eststo, title("`x'") : areg `x'_2018 `x'_2015 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum `x'_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	* Facebook and spillover effects by quartile, interactive controls
	eststo, title("`x'") : areg `x'_2018 `x'_2015 any_facebook_treatment##quartiles spillover##quartiles $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum `x'_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	restore
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* Facebook and spillover effects by saturation and quartile
	eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation##quartiles $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	restore
}
quietly {
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1c F_test_1d F_test_3c F_test_3d ///
		F_test_5 F_test_6 F_test_7 F_test_8 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low below median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low below median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*)	
	esttab est* using "Tables\full_table_by_quartile.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1c F_test_1d F_test_3c F_test_3d ///
		F_test_5 F_test_6 F_test_7 F_test_8 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low below median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low below median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace	
}



*** Table H.2: Effect of Facebook ads on precinct-level municipal incumbent party vote share, by municipal mobility range
quietly {
	preserve
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	* Standardize movement range moderator
	sum mr2 [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
	replace mr2 = (mr2 - `r(mean)')/`r(sd)'
	label var mr2 "Movement range"
	** Regressions
	eststo clear
	foreach k in above_malf_median quartiles {
		* Facebook and spillover effects by saturation and quartile
		eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##`k'##c.mr2 [aweight=segment_pooled_CK_weight], ///
			cluster(code_INEGI) a(id_block)
		sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		sum mr2 [aweight=segment_pooled_CK_weight] if e(sample)
		estadd scalar Mean_MR = `r(mean)'
	}
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome Mean_MR, fmt(%9.0fc %9.0fc 2 2 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." "Mean movement range")) ///
		starlevels(* .1 ** .05 *** .01) keep(*facebook_saturation*mr2) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" ///
		facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *1.quartiles* *0.above_malf_median*) ///
		order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*)
	esttab est* using "Tables\HEs_muni_inc_vote_share_by_median_and_quartile_by_mr2.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome Mean_MR, fmt(%9.0fc %9.0fc 2 2 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." "Mean movement range")) ///
		starlevels(* .1 ** .05 *** .01) keep(*facebook_saturation*mr2) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" ///
		facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *1.quartiles* *0.above_malf_median*) ///
		order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
	restore
}



*** Table H.3: Effect of adjacent directly treated segments being part of a different campaign on precinct-level municipal incumbent party vote share
quietly {
	preserve
	** Clean data for segments within the same municipality and consider only precincts within 10 kms of other segments in municipalities where CK and NCK could differ
	* Open data for precinct-segment pairs where each precinct is matched to other precincts with a distance to each
	use "Datasets\DIST_S_ALL.dta", clear
	* Remove precinct-segments pairs that match the precinct to its own segment
	merge m:1 precinct code_INEGI using "Datasets\Main_Precinct_Dataset.dta", keepusing(segment)
	keep if _merge==3
	drop _merge
	drop if segment==SEGMENT
	* Drop precinct-segment pairs where the precinct is more than 0.1 kms away from the segment
	drop if DIST>0.1
	* Keep only treated precincts that are near to other treated segments
	keep if TREATMENT!="C" & TREATMENT_S!="C"
	* Keep only municipalities within which there is within-municipality variation in whether segments got CK or NCK versions of treatment
	keep if SATURATION_S=="High saturation" | (SATURATION_S=="Low saturation" & NUMBER_OF_SEGMENT>5)
	* Count total nearby and different nearby treated segments
	bysort code_INEGI precinct : g nearby_treated_segments = _N
	g diff = TREATMENT!=TREATMENT_S
	bysort code_INEGI precinct : egen nearby_diff_treated_segments = sum(diff)
	* Keep relevant variables for merging back into election results dataset and collapse dataset to precinct level
	keep precinct code_INEGI nearby*
	duplicates drop
	g sh_nearby_diff_treated_segments = nearby_diff_treated_segments / nearby_treated_segments
	save "merge.dta", replace
	restore
	** Merge in nearby segments data
	preserve
	merge 1:1 precinct code_INEGI using "merge.dta"
	keep if _merge==3
	drop _merge
	erase "merge.dta"
	** Prepare data
	* Compute segment weights in the subsample to weight each segment equally
	reghdfe muni_inc_vote_share_2018 muni_inc_vote_share_2015 c.sh_nearby_diff_treated_segments##quartiles, a(code_INEGI nearby_treated_segments##quartiles)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	g new_weight = muni_listanominal_2018 / replacement
	* New cluster level
	egen new_cluster = group(code_INEGI segment)
	** Regressions
	eststo clear
	foreach k of varlist above_malf_median quartiles {
		eststo, title("0.1 kms") : reghdfe muni_inc_vote_share_2018 muni_inc_vote_share_2015 c.sh_nearby_diff_treated_segments##`k' [aweight=new_weight], ///
			cluster(new_cluster) a(code_INEGI nearby_treated_segments##`k')
		sum muni_inc_vote_share_2018 [aweight=new_weight] if e(sample)
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		sum sh_nearby_diff_treated_segments [aweight=new_weight] if e(sample)
		estadd scalar Mean_Treatment = `r(mean)'
		estadd scalar SD_Treatment = `r(sd)'
	}
	restore
	** Make table
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome Mean_Treatment SD_Treatment, fmt(%9.0fc %9.0fc 2 2 2 3 3 3 3 3) ///
		labels("Observations" "Number of municipality $\times$ segment clusters" "$ R^2$" "Outcome mean" "Outcome std. dev." "Share of adjacent treated segments in a different ad campaign mean" ///
		"Share of adjacent treated segments in a different ad campaign std. dev.")) starlevels(* .1 ** .05 *** .01) ///
		keep(*sh_nearby_diff_treated_segments) drop(1.quartiles* 0.above_malf_median*) label ///
		varlabel(sh_nearby_diff_treated_segments "Share of adjacent treated segments in a different ad campaign" ///
		1.above_malf_median#c.sh_nearby_diff_treated_segments "Share of adjacent treated segments in a different ad campaign $\times$ Above median irregularities" ///
		3.quartiles#c.sh_nearby_diff_treated_segments "Share of adjacent treated segments in a different ad campaign $\times$ Irregularities Q3" ///
		4.quartiles#c.sh_nearby_diff_treated_segments "Share of adjacent treated segments in a different ad campaign $\times$ Irregularities Q4")
	esttab est* using "Tables\spillover_test_muni_inc_vote_share_CK_NCK_within.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome Mean_Treatment SD_Treatment, fmt(%9.0fc %9.0fc 2 2 2 3 3 3 3 3) ///
		labels("Observations" "Number of municipality $\times$ segment clusters" "$ R^2$" "Outcome mean" "Outcome std. dev." "Share of adjacent treated segments in a different ad campaign mean" ///
		"Share of adjacent treated segments in a different ad campaign std. dev.")) starlevels(* .1 ** .05 *** .01) ///
		keep(*sh_nearby_diff_treated_segments) drop(1.quartiles* 0.above_malf_median*) label ///
		varlabel(sh_nearby_diff_treated_segments "Share of adjacent treated segments in a different ad campaign" ///
		1.above_malf_median#c.sh_nearby_diff_treated_segments "Share of adjacent treated segments in a different ad campaign $\times$ Above median irregularities" ///
		3.quartiles#c.sh_nearby_diff_treated_segments "Share of adjacent treated segments in a different ad campaign $\times$ Irregularities Q3" ///
		4.quartiles#c.sh_nearby_diff_treated_segments "Share of adjacent treated segments in a different ad campaign $\times$ Irregularities Q4") replace
}



*** Table H.4: Effect of Facebook ads on precinct-level municipal incumbent party vote share, excluding the lagged dependent variable
quietly {
	eststo clear
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* ATE, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 1.any_facebook_treatment 1.spillover [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	* Facebook and spillover effects by median, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by median, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 any_facebook_treatment##above_malf_median spillover##above_malf_median $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by quartile, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	* Facebook and spillover effects by quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 any_facebook_treatment##quartiles spillover##quartiles $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	restore
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* Facebook and spillover effects by saturation
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 i.facebook_saturation [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_1 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_2 = `r(p)'
	* Facebook and spillover effects by saturation and quartile
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 i.facebook_saturation##above_malf_median $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and quartile
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 i.facebook_saturation##quartiles $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	restore
	** Make table
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*)	
	esttab est* using "Tables\full_table_muni_inc_vote_share_no_LDV.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
}



*** Table H.5: Effect of Facebook ads on precinct-level municipal incumbent party vote share, weighting by registered voters
quietly {
	eststo clear
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=muni_listanominal_2018/pooled_CK_sat_prob], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=muni_listanominal_2018/pooled_CK_sat_prob], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=muni_listanominal_2018/pooled_CK_sat_prob] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* ATE, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 1.any_facebook_treatment 1.spillover [aweight=muni_listanominal_2018/pooled_CK_sat_prob], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_sat_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	* Facebook and spillover effects by median, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_sat_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by median, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median $any_facebook_treatment_controls $spillover_controls ///
		[aweight=muni_listanominal_2018/pooled_CK_sat_prob], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_sat_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by quartile, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=muni_listanominal_2018/pooled_CK_sat_prob], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_sat_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	* Facebook and spillover effects by quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles $any_facebook_treatment_controls $spillover_controls ///
		[aweight=muni_listanominal_2018/pooled_CK_sat_prob], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_sat_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	restore
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=muni_listanominal_2018/pooled_CK_prob], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=muni_listanominal_2018/pooled_CK_prob], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=muni_listanominal_2018/pooled_CK_prob] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* Facebook and spillover effects by saturation
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation [aweight=muni_listanominal_2018/pooled_CK_prob], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_1 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_2 = `r(p)'
	* Facebook and spillover effects by saturation and quartile
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median [aweight=muni_listanominal_2018/pooled_CK_prob], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median $facebook_saturation_controls ///
		[aweight=muni_listanominal_2018/pooled_CK_prob], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and quartile
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=muni_listanominal_2018/pooled_CK_prob], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles $facebook_saturation_controls [aweight=muni_listanominal_2018/pooled_CK_prob], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=muni_listanominal_2018/pooled_CK_prob] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	restore
	** Make table
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*)	
	esttab est* using "Tables\full_table_muni_inc_vote_share_pop_weights.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
}



*** Table H.6: Effect of Facebook ads on precinct-level municipal incumbent party vote share, weighting municipalities with different numbers of segments equally
quietly {
	eststo clear
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=segment_pooled_CK_sat_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=segment_pooled_CK_sat_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight/number_of_segments] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* ATE, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 1.any_facebook_treatment 1.spillover [aweight=segment_pooled_CK_sat_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	* Facebook and spillover effects by median, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
		[aweight=segment_pooled_CK_sat_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by median, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by quartile, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=segment_pooled_CK_sat_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	* Facebook and spillover effects by quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	restore
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight/number_of_segments] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* Facebook and spillover effects by saturation
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation [aweight=segment_pooled_CK_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_1 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_2 = `r(p)'
	* Facebook and spillover effects by saturation and quartile
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median $facebook_saturation_controls ///
		[aweight=segment_pooled_CK_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and quartile
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles $facebook_saturation_controls ///
		[aweight=segment_pooled_CK_weight/number_of_segments], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight/number_of_segments] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	restore
	** Make table
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*)	
	esttab est* using "Tables\full_table_muni_inc_vote_share_equal_munis.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, fmt(%9.0fc %9.0fc 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
}



*** Table H.7: Effect of Facebook ads on precinct-level municipal incumbent party vote share, where the outcome denominator is the share of registered voters
quietly {
	eststo clear
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* ATE, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 1.any_facebook_treatment 1.spillover [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_reg_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	* Facebook and spillover effects by median, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by median, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#1.above_malf_median = 0
	estadd scalar F_test_1b = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#1.above_malf_median = 0
	estadd scalar F_test_3b = `r(p)'
	* Facebook and spillover effects by quartile, no interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 any_facebook_treatment##quartiles spillover##quartiles ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	* Facebook and spillover effects by quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 any_facebook_treatment##quartiles spillover##quartiles $any_facebook_treatment_controls $spillover_controls ///
		[aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_sat_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 1.any_facebook_treatment = 0
	estadd scalar F_test_1a = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#3.quartiles = 0
	estadd scalar F_test_1c = `r(p)'
	test 1.any_facebook_treatment + 1.any_facebook_treatment#4.quartiles = 0
	estadd scalar F_test_1d = `r(p)'
	test 1.spillover + 1.spillover = 0
	estadd scalar F_test_3a = `r(p)'
	test 1.spillover + 1.spillover#3.quartiles = 0
	estadd scalar F_test_3c = `r(p)'
	test 1.spillover + 1.spillover#4.quartiles = 0
	estadd scalar F_test_3d = `r(p)'
	restore
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	foreach k of varlist $controls {
		sum `k' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `k' = (`k' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`k'
		global spillover_controls $spillover_controls spillover_control##c.`k'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`k'
	}
	** Regressions
	* Facebook and spillover effects by saturation
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 i.facebook_saturation [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_reg_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_1 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_2 = `r(p)'
	* Facebook and spillover effects by saturation and median
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_reg_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and median, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 i.facebook_saturation##above_malf_median $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_reg_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
	estadd scalar F_test_3 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
	estadd scalar F_test_4 = `r(p)'
	* Facebook and spillover effects by saturation and quartile
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_reg_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	* Facebook and spillover effects by saturation and quartile, interactive controls
	eststo, title("muni_inc_vote_share") : areg muni_inc_vote_reg_share_2018 muni_inc_vote_reg_share_2015 i.facebook_saturation##quartiles $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	sum muni_inc_vote_reg_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
	estadd scalar clusters = e(N_clust)
	estadd scalar Mean_Outcome = `r(mean)'
	estadd scalar SD_Outcome = `r(sd)'
	test 4.facebook_saturation == 2.facebook_saturation
	estadd scalar F_test_5 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
	estadd scalar F_test_6 = `r(p)'
	test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
	estadd scalar F_test_7 = `r(p)'
	test 3.facebook_saturation == 1.facebook_saturation
	estadd scalar F_test_8 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
	estadd scalar F_test_9 = `r(p)'
	test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
	estadd scalar F_test_10 = `r(p)'
	restore
	*** Outputs
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, ///
		fmt(%9.0fc %9.0fc 2) labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*)	
	esttab est* using "Tables\full_table_muni_inc_vote_share.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1a F_test_1b F_test_1c F_test_1d F_test_3a F_test_3b F_test_3c F_test_3d ///
		F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, ///
		fmt(%9.0fc %9.0fc 2) labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: null direct effect below median ($ p$ value)" "Test: null direct effect above median ($ p$ value)" ///
		"Test: null direct effect in Q3 ($ p$ value)" "Test: null direct effect in Q4 ($ p$ value)" ///
		"Test: null indirect effect below median ($ p$ value)" "Test: null indirect effect above median ($ p$ value)" ///
		"Test: null indirect effect in Q3 ($ p$ value)" "Test: null indirect effect in Q4 ($ p$ value)" ///
		"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
		"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
		"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
		"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
		"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(*any_facebook_treatment* *spillover* *facebook_saturation*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" ///
		any_facebook_treatment "Facebook ads" facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *control* *1.quartiles *0.above_malf_median) ///
		order(*any_facebook_treatment* *spillover* 4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
}



*** Figure H.1: Leave-one-out estimates (dropping each randomization block) of the average treatment effect of Facebook ads on incumbent party vote share in the municipalities where below-median irregularities occurred

** (a) Conditional average treatment effect and (b) Conditional average indirect effect
quietly {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	** Save coefficients from regressions
	g block = _n
	g treat_est = .
	g treat_ci_upper = .
	g treat_ci_lower = .
	g spill_est = .
	g spill_ci_upper = .
	g spill_ci_lower = .
	egen block_id = group(id_block)
	sum block_id, meanonly
	foreach b of num 1/`r(max)' {
		areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##above_malf_median spillover##above_malf_median ///
			if id_block!=`b' [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
		replace treat_est = _b[1.any_facebook_treatment] if _n==`b'
		replace treat_ci_upper = _b[1.any_facebook_treatment] + 1.96 * _se[1.any_facebook_treatment] if _n==`b'
		replace treat_ci_lower = _b[1.any_facebook_treatment] - 1.96 * _se[1.any_facebook_treatment] if _n==`b'
		replace spill_est = _b[1.spillover] if _n==`b'
		replace spill_ci_upper = _b[1.spillover] + 1.96 * _se[1.spillover] if _n==`b'
		replace spill_ci_lower = _b[1.spillover] - 1.96 * _se[1.spillover] if _n==`b'
	}
	** Makes figures
	twoway (rcap treat_ci_lower treat_ci_upper block, vertical lcolor(gray) lwidth(thick)) ///
		(scatter treat_est block, mcolor(black) msize(large)) if block<=42, ///
		legend(off) xlab(1(1)42, labsize(vsmall) valuelabel nogrid) ylab(, nogrid) yline(0, lcolor(black) lpattern(dash)) ///
		ytitle("Treatment effect on vote share") title("") xtitle("Block removed") graphregion(fcolor(white) lcolor(white)) ///
		xscale(titlegap(3)) yscale(titlegap(3)) graphregion(margin(0 2 0 0))
	graph export "Figures\treatment_removing_blocks.pdf", as(pdf) replace
	twoway (rcap spill_ci_lower spill_ci_upper block, vertical lcolor(gray) lwidth(thick)) ///
		(scatter spill_est block, mcolor(black) msize(large)) if block<=42, ///
		legend(off) xlab(1(1)42, labsize(vsmall) valuelabel nogrid) ylab(, nogrid) yline(0, lcolor(black) lpattern(dash)) ///
		ytitle("Spillover effect on vote share") title("") xtitle("Block removed") graphregion(fcolor(white) lcolor(white)) ///
		xscale(titlegap(3)) yscale(titlegap(3)) graphregion(margin(0 2 0 0))
	graph export "Figures\spillover_removing_blocks.pdf", as(pdf) replace
	restore
}


** (c) Conditional average treatment effect in high saturation municipalities, (d) Conditional average indirect effect in high saturation municipalities, (e) Difference in conditional average treatment effect between high and low saturation municipalities, (f) Difference in conditional indirect treatment effect between high and low saturation municipalities
quietly {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	** Save coefficients from regressions
	g block = _n
	g treat_est = .
	g treat_ci_upper = .
	g treat_ci_lower = .
	g spill_est = .
	g spill_ci_upper = .
	g spill_ci_lower = .
	g diff_treat_est = .
	g diff_treat_ci_upper = .
	g diff_treat_ci_lower = .
	g diff_spill_est = .
	g diff_spill_ci_upper = .
	g diff_spill_ci_lower = .
	egen block_id = group(id_block)
	sum block_id, meanonly
	foreach b of num 1/`r(max)' {
		areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##above_malf_median ///
			if id_block!=`b' [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		replace treat_est = _b[4.facebook_saturation] if _n==`b'
		replace treat_ci_upper = _b[4.facebook_saturation] + 1.96 * _se[4.facebook_saturation] if _n==`b'
		replace treat_ci_lower = _b[4.facebook_saturation] - 1.96 * _se[4.facebook_saturation] if _n==`b'
		replace spill_est = _b[3.facebook_saturation] if _n==`b'
		replace spill_ci_upper = _b[3.facebook_saturation] + 1.96 * _se[3.facebook_saturation] if _n==`b'
		replace spill_ci_lower = _b[3.facebook_saturation] - 1.96 * _se[3.facebook_saturation] if _n==`b'
		lincom _b[4.facebook_saturation] - _b[2.facebook_saturation]
		replace diff_treat_est = `r(estimate)' if _n==`b'
		replace diff_treat_ci_upper = `r(estimate)' + 1.96 * `r(se)' if _n==`b'
		replace diff_treat_ci_lower = `r(estimate)' - 1.96 * `r(se)' if _n==`b'
		lincom _b[3.facebook_saturation] - _b[1.facebook_saturation]
		replace diff_spill_est = `r(estimate)' if _n==`b'
		replace diff_spill_ci_upper = `r(estimate)' + 1.96 * `r(se)' if _n==`b'
		replace diff_spill_ci_lower = `r(estimate)' - 1.96 * `r(se)' if _n==`b'
	}
	** Makes figures
	twoway (rcap treat_ci_lower treat_ci_upper block, vertical lcolor(gray) lwidth(thick)) ///
		(scatter treat_est block, mcolor(black) msize(large)) if block<=42, ///
		legend(off) xlab(1(1)42, labsize(vsmall) valuelabel nogrid) ylab(, nogrid) yline(0, lcolor(black) lpattern(dash)) ///
		ytitle("Treatment effect on vote share") title("") xtitle("Block removed") graphregion(fcolor(white) lcolor(white)) ///
		xscale(titlegap(3)) yscale(titlegap(3)) graphregion(margin(0 2 0 0))
	graph export "Figures\treatment_H_removing_blocks.pdf", as(pdf) replace
	twoway (rcap spill_ci_lower spill_ci_upper block, vertical lcolor(gray) lwidth(thick)) ///
		(scatter spill_est block, mcolor(black) msize(large)) if block<=42, ///
		legend(off) xlab(1(1)42, labsize(vsmall) valuelabel nogrid) ylab(, nogrid) yline(0, lcolor(black) lpattern(dash)) ///
		ytitle("Spillover effect on vote share") title("") xtitle("Block removed") graphregion(fcolor(white) lcolor(white)) ///
		xscale(titlegap(3)) yscale(titlegap(3)) graphregion(margin(0 2 0 0))
	graph export "Figures\spillover_H_removing_blocks.pdf", as(pdf) replace
	twoway (rcap diff_treat_ci_lower diff_treat_ci_upper block, vertical lcolor(gray) lwidth(thick)) ///
		(scatter diff_treat_est block, mcolor(black) msize(large)) if block<=42, ///
		legend(off) xlab(1(1)42, labsize(vsmall) valuelabel nogrid) ylab(, nogrid) yline(0, lcolor(black) lpattern(dash)) ///
		ytitle("Differential treatment effect on vote" "share in high saturation municipalities") title("") xtitle("Block removed") graphregion(fcolor(white) lcolor(white)) ///
		xscale(titlegap(3)) yscale(titlegap(3)) graphregion(margin(0 2 0 0))
	graph export "Figures\differential_treatment_removing_blocks.pdf", as(pdf) replace
	twoway (rcap diff_spill_ci_lower diff_spill_ci_upper block, vertical lcolor(gray) lwidth(thick)) ///
		(scatter diff_spill_est block, mcolor(black) msize(large)) if block<=42, ///
		legend(off) xlab(1(1)42, labsize(vsmall) valuelabel nogrid) ylab(, nogrid) yline(0, lcolor(black) lpattern(dash)) ///
		ytitle("Differential spillover effect on vote" "share in high saturation municipalities") title("") xtitle("Block removed") graphregion(fcolor(white) lcolor(white)) ///
		xscale(titlegap(3)) yscale(titlegap(3)) graphregion(margin(0 2 0 0))
	graph export "Figures\differential_spillover_removing_blocks.pdf", as(pdf) replace
	restore
}



*** Table I.1: Effect of municipal treatments on municipal Facebook engagement, by common knowledge treatment
quietly {
	preserve
	use "Datasets\facebook_ads.dta", clear
	** Regressions
	eststo clear
	foreach x of varlist PaidImpressions Organicimpressions PaidReach OrganicReach PageEngagedUsers TotalVideoViews TotalUniqueVideoViews Total30SecondViews TotalUnique30SecondV {
		eststo, title("`x'") : reg `x' i.treatment_type if treatment_type>0, ro
		sum `x' if e(sample) & treatment_type==1
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
	}
	** Make table
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
		labels("Observations" "$ R^2$" "No common knowledge outcome mean" "No common knowledge std. dev.")) starlevels(* .1 ** .05 *** .01) keep(2.treatment_type) label ///
		varlabel(2.treatment_type "Facebook ads (common knowledge)")
	esttab est* using "Tables\first_stage_by_CK_2_no_control.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome, fmt(%9.0fc 2 2 2 3) ///
		labels("Observations" "$ R^2$" "No common knowledge outcome mean" "No common knowledge std. dev.")) starlevels(* .1 ** .05 *** .01) keep(2.treatment_type) label ///
		varlabel(2.treatment_type "Facebook ads (common knowledge)") replace
	restore
}



*** Table I.2: Differential effects of Facebook ads on precinct-level municipal incumbent party vote share, by common knowledge treatment
quietly {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment spillover [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace segment_pooled_sat_weight = muni_listanominal_2018 / (replacement * full_prob)
	replace segment_full_weight = muni_listanominal_2018 / (replacement * pooled_CK_prob)
	* Define and label CK treatment
	g facebook_ck = facebook_treatment
	replace facebook_ck = 2 if facebook_common_treatment==1
	label define facebook_ck 0 "Control" 1 "Direct effect" 2 "Direct effect + CK"
	label values facebook_ck facebook_ck
	** Regressions
	eststo clear
	foreach x in muni_inc_vote_share muni_turnout {
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_ck spillover [aweight=segment_pooled_sat_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_sat_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_ck##above_malf_median i.spillover##above_malf_median [aweight=segment_pooled_sat_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_sat_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_ck##quartiles i.spillover##quartiles [aweight=segment_pooled_sat_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_sat_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_full_saturation [aweight=segment_full_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_full_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_full_saturation##above_malf_median [aweight=segment_full_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_full_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_full_saturation##quartiles [aweight=segment_full_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_full_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
	}
	** Make table
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome, fmt(%9.0fc %9.0fc 2 2 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev.")) ///
		starlevels(* .1 ** .05 *** .01) keep(*facebook_full_saturation* *facebook_ck* *spillover*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" spillover "Indirect effect" ///
		facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") ///
		drop(0.* *1.quartiles *0.above_malf_median) order(1.facebook_ck* 2.facebook_ck* *spillover* 5.facebook_full_saturation* 6.facebook_full_saturation* ///
		2.facebook_full_saturation* 3.facebook_full_saturation* 4.facebook_full_saturation* 1.facebook_full_saturation*)
	esttab est* using "Tables\HEs_vote_turnout_by_median_quartile_CK.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome, fmt(%9.0fc %9.0fc 2 2 2) ///
		labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev.")) ///
		starlevels(* .1 ** .05 *** .01) keep(*facebook_full_saturation* *facebook_ck* *spillover*) label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" spillover "Indirect effect" ///
		facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") ///
		drop(0.* *1.quartiles *0.above_malf_median) order(1.facebook_ck* 2.facebook_ck* *spillover* 5.facebook_full_saturation* 6.facebook_full_saturation* ///
		2.facebook_full_saturation* 3.facebook_full_saturation* 4.facebook_full_saturation* 1.facebook_full_saturation*) replace
	restore
}



*** Table I.3: Effect of Facebook ads on precinct-level ENPV, by information campaign saturation
*** Table I.4: Effect of Facebook ads on segment-level ENPV, by information campaign saturation
*** Table I.5: Effect of Facebook ads on the precinct-level Golosov index of the effective number of political parties, by information campaign saturation
*** Table I.6: Effect of Facebook ads on the segment-level Golosov index of the effective number of political parties, by information campaign saturation
quietly {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	** Regressions
	foreach x in ENPV_precinct ENPV_segment golosov_precinct golosov_segment {
		eststo clear
		* Facebook and spillover effects by saturation
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 4.facebook_saturation == 2.facebook_saturation
		estadd scalar F_test_1 = `r(p)'
		test 3.facebook_saturation == 1.facebook_saturation
		estadd scalar F_test_2 = `r(p)'
		* Facebook and spillover effects by saturation and quartile
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation##above_malf_median [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 4.facebook_saturation == 2.facebook_saturation
		estadd scalar F_test_5 = `r(p)'
		test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
		estadd scalar F_test_3 = `r(p)'
		test 3.facebook_saturation == 1.facebook_saturation
		estadd scalar F_test_8 = `r(p)'
		test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
		estadd scalar F_test_4 = `r(p)'
		* Facebook and spillover effects by saturation and quartile, interactive controls
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation##above_malf_median $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 4.facebook_saturation == 2.facebook_saturation
		estadd scalar F_test_5 = `r(p)'
		test 4.facebook_saturation#1.above_malf_median == 2.facebook_saturation#1.above_malf_median
		estadd scalar F_test_3 = `r(p)'
		test 3.facebook_saturation == 1.facebook_saturation
		estadd scalar F_test_8 = `r(p)'
		test 3.facebook_saturation#1.above_malf_median == 1.facebook_saturation#1.above_malf_median
		estadd scalar F_test_4 = `r(p)'
		* Facebook and spillover effects by saturation and quartile
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation##quartiles [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 4.facebook_saturation == 2.facebook_saturation
		estadd scalar F_test_5 = `r(p)'
		test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
		estadd scalar F_test_6 = `r(p)'
		test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
		estadd scalar F_test_7 = `r(p)'
		test 3.facebook_saturation == 1.facebook_saturation
		estadd scalar F_test_8 = `r(p)'
		test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
		estadd scalar F_test_9 = `r(p)'
		test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
		estadd scalar F_test_10 = `r(p)'
		* Facebook and spillover effects by saturation and quartile, interactive controls
		eststo, title("`x'") : areg `x'_2018 `x'_2015 i.facebook_saturation##quartiles $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum `x'_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 4.facebook_saturation == 2.facebook_saturation
		estadd scalar F_test_5 = `r(p)'
		test 4.facebook_saturation + 4.facebook_saturation#3.quartiles == 2.facebook_saturation + 2.facebook_saturation#3.quartiles
		estadd scalar F_test_6 = `r(p)'
		test 4.facebook_saturation + 4.facebook_saturation#4.quartiles == 2.facebook_saturation + 2.facebook_saturation#4.quartiles
		estadd scalar F_test_7 = `r(p)'
		test 3.facebook_saturation == 1.facebook_saturation
		estadd scalar F_test_8 = `r(p)'
		test 3.facebook_saturation + 3.facebook_saturation#3.quartiles == 1.facebook_saturation#3.quartiles
		estadd scalar F_test_9 = `r(p)'
		test 3.facebook_saturation + 3.facebook_saturation#4.quartiles == 1.facebook_saturation#4.quartiles
		estadd scalar F_test_10 = `r(p)'
		** Make tables
		noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, ///
			fmt(%9.0fc %9.0fc 2) labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
			"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
			"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
			"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
			"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
			"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
			starlevels(* .1 ** .05 *** .01) keep(*facebook_saturation*) label ///
			varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" ///
			facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") ///
			drop(0.* *control* *1.quartiles *0.above_malf_median) order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*)
		esttab est* using "Tables\HEs_`x'_by_median_and_quartiles_and_saturation.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
			cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome F_test_1 F_test_5 F_test_3 F_test_6 F_test_7 F_test_2 F_test_8 F_test_4 F_test_9 F_test_10, ///
			fmt(%9.0fc %9.0fc 2) labels("Observations" "Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
			"Test: same direct effect in high and low ($ p$ value)" "Test: same direct effect in high and low below median ($ p$ value)" ///
			"Test: same direct effect in high and low above median ($ p$ value)" "Test: same direct effect in high and low in Q3 ($ p$ value)" /// 
			"Test: same direct effect in high and low in Q4 ($ p$ value)" "Test: same indirect effect in high and low ($ p$ value)" ///
			"Test: same indirect effect in high and low below median ($ p$ value)" "Test: same indirect effect in high and low above median ($ p$ value)" ///
			"Test: same indirect effect in high and low in Q3 ($ p$ value)" "Test: same indirect effect in high and low in Q4 ($ p$ value)")) ///
			starlevels(* .1 ** .05 *** .01) keep(*facebook_saturation*) label ///
			varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" ///
			facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") ///
			drop(0.* *control* *1.quartiles *0.above_malf_median) order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
	}
	restore
}



*** Table I.7: Effect of Facebook ad campaigns on municipal-level newspaper reporting on corruption in general
quietly {
	** Prepare newspaper data for merging into main dataset
	preserve
	import excel "Datasets\Newspapers.xls", firstrow clear
	keep if ourdates==1
	g mentioning = directmentioning + indirectmentioning
	bysort inegi : egen muni_circulation = mean(total_circulation)
	foreach x in directmentioning indirectmentioning mentioning generalcorruption {
		g `x'_circ_weighted = `x' * total_circulation / muni_circulation
	}
	collapse (sum) directmentioning* indirectmentioning* mentioning* generalcorruption*, by(inegi)
	rename inegi code_INEGI
	save "merge.dta", replace
	restore
	preserve
	* Collapse main dataset to municipality level, the unit of analysis for newspapers, and merge in newspaper data
	duplicates drop code_INEGI, force
	merge 1:1 code_INEGI using "merge.dta"
	drop if _merge==2
	drop _merge
	erase "merge.dta"
	* Set municipalities without a registered newspaper to zero
	foreach x of varlist directmentioning-generalcorruption_circ_weighted {
		replace `x' = 0 if `x'==.
	}
	eststo clear
	** Prepare data
	* Define the set of standardized linear controls
	global controls "Audit_Year Auditados mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	global any_saturation_controls ""
	global saturation_treatment_controls ""
	g control_any_saturation_treatment = any_saturation_treatment
	g control_saturation_treatment = saturation_treatment
	areg generalcorruption 1.any_saturation_treatment, ro a(id_block)
	foreach x of varlist $controls {
		sum `x' if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_saturation_controls $any_saturation_controls 1.control_any_saturation_treatment##c.`x'
		global saturation_treatment_controls $saturation_treatment_controls i.control_saturation_treatment##c.`x'
	}
	** Regressions
	foreach y in generalcorruption generalcorruption_circ_weighted {
		eststo, title("`y'") : areg `y' 1.any_saturation_treatment, ro a(id_block)
		sum `y' if e(sample) & any_saturation_treatment==0
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		
		eststo, title("`y'") : areg `y' any_saturation_treatment##above_malf_median, ro a(id_block)
		sum `y' if e(sample) & any_saturation_treatment==0
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 1.any_saturation_treatment = 0
		estadd scalar F_test_Q1 = `r(p)'
		test 1.any_saturation_treatment + 1.any_saturation_treatment#1.above_malf_median = 0
		estadd scalar F_test_above = `r(p)'
		eststo, title("`y'") : areg `y' any_saturation_treatment##above_malf_median $any_saturation_controls, ro a(id_block)
		sum `y' if e(sample) & any_saturation_treatment==0
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 1.any_saturation_treatment = 0
		estadd scalar F_test_Q1 = `r(p)'
		test 1.any_saturation_treatment + 1.any_saturation_treatment#1.above_malf_median = 0
		estadd scalar F_test_above = `r(p)'

		eststo, title("`y'") : areg `y' any_saturation_treatment##quartiles, ro a(id_block)
		sum `y' if e(sample) & any_saturation_treatment==0
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 1.any_saturation_treatment = 0
		estadd scalar F_test_Q1 = `r(p)'
		test 1.any_saturation_treatment + 1.any_saturation_treatment#3.quartiles = 0
		estadd scalar F_test_Q3 = `r(p)'
		test 1.any_saturation_treatment + 1.any_saturation_treatment#4.quartiles = 0
		estadd scalar F_test_Q4 = `r(p)'
		eststo, title("`y'") : areg `y' any_saturation_treatment##quartiles $any_saturation_controls, ro a(id_block)
		sum `y' if e(sample) & any_saturation_treatment==0
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 1.any_saturation_treatment = 0
		estadd scalar F_test_Q1 = `r(p)'
		test 1.any_saturation_treatment + 1.any_saturation_treatment#3.quartiles = 0
		estadd scalar F_test_Q3 = `r(p)'
		test 1.any_saturation_treatment + 1.any_saturation_treatment#4.quartiles = 0
		estadd scalar F_test_Q4 = `r(p)'

		eststo, title("`y'") : areg `y' i.saturation_treatment, ro a(id_block)
		sum `y' if e(sample) & saturation_treatment==1
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 2.saturation_treatment == 3.saturation_treatment
		estadd scalar F_test = `r(p)'
		
		eststo, title("`y'") : areg `y' i.saturation_treatment##above_malf_median, ro a(id_block)
		sum `y' if e(sample) & saturation_treatment==1
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 2.saturation_treatment = 0
		estadd scalar F_test_Q1_1 = `r(p)'
		test 2.saturation_treatment + 3.saturation_treatment#1.above_malf_median = 0
		estadd scalar F_test_above_1 = `r(p)'
		test 3.saturation_treatment = 0
		estadd scalar F_test_Q1_2 = `r(p)'
		test 3.saturation_treatment + 3.saturation_treatment#1.above_malf_median = 0
		estadd scalar F_test_above_2 = `r(p)'
		eststo, title("`y'") : areg `y' i.saturation_treatment##above_malf_median $saturation_treatment_controls, ro a(id_block)
		sum `y' if e(sample) & saturation_treatment==1
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 2.saturation_treatment = 0
		estadd scalar F_test_Q1_1 = `r(p)'
		test 2.saturation_treatment + 3.saturation_treatment#1.above_malf_median = 0
		estadd scalar F_test_above_1 = `r(p)'
		test 3.saturation_treatment = 0
		estadd scalar F_test_Q1_2 = `r(p)'
		test 3.saturation_treatment + 3.saturation_treatment#1.above_malf_median = 0
		estadd scalar F_test_above_2 = `r(p)'

		eststo, title("`y'") : areg `y' i.saturation_treatment##quartiles, ro a(id_block)
		sum `y' if e(sample) & saturation_treatment==1
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 2.saturation_treatment = 0
		estadd scalar F_test_Q1_1 = `r(p)'
		test 2.saturation_treatment + 2.saturation_treatment#3.quartiles = 0
		estadd scalar F_test_Q3_1 = `r(p)'
		test 2.saturation_treatment + 2.saturation_treatment#4.quartiles = 0
		estadd scalar F_test_Q4_1 = `r(p)'
		test 3.saturation_treatment = 0
		estadd scalar F_test_Q1_2 = `r(p)'
		test 3.saturation_treatment + 3.saturation_treatment#3.quartiles = 0
		estadd scalar F_test_Q3_2 = `r(p)'
		test 3.saturation_treatment + 3.saturation_treatment#4.quartiles = 0
		estadd scalar F_test_Q4_2 = `r(p)'
		eststo, title("`y'") : areg `y' i.saturation_treatment##quartiles $saturation_treatment_controls, ro a(id_block)
		sum `y' if e(sample) & saturation_treatment==1
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		test 2.saturation_treatment = 0
		estadd scalar F_test_Q1_1 = `r(p)'
		test 2.saturation_treatment + 2.saturation_treatment#3.quartiles = 0
		estadd scalar F_test_Q3_1 = `r(p)'
		test 2.saturation_treatment + 2.saturation_treatment#4.quartiles = 0
		estadd scalar F_test_Q4_1 = `r(p)'
		test 3.saturation_treatment = 0
		estadd scalar F_test_Q1_2 = `r(p)'
		test 3.saturation_treatment + 3.saturation_treatment#3.quartiles = 0
		estadd scalar F_test_Q3_2 = `r(p)'
		test 3.saturation_treatment + 3.saturation_treatment#4.quartiles = 0
		estadd scalar F_test_Q4_2 = `r(p)'
	}
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome F_test_Q1 F_test_above F_test_Q3 F_test_Q4 ///
		F_test F_test_Q1_1 F_test_above_1 F_test_Q3_1 F_test_Q4_1 F_test_Q1_2 F_test_above_2 F_test_Q3_2 F_test_Q4_2, fmt(%9.0fc 2 2 2) ///
		labels("Observations" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: effect of treatment below median ($ p$ value)" "Test: effect of treatment above median ($ p$ value)" ///
		"Test: effect of treatment in Q3 ($ p$ value)" "Test: effect of treatment in Q4 ($ p$ value)" "Test: low = high ($ p$ value)" ///
		"Test: effect of low saturation below median ($ p$ value)" "Test: effect of low saturation above median ($ p$ value)" ///
		"Test: effect of low saturation in Q3 ($ p$ value)" "Test: effect of low saturation in Q4 ($ p$ value)" ///
		"Test: effect of high saturation in Q3 ($ p$ value)" "Test: effect of high saturation in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(1.any_saturation_treatment* 2.saturation_treatment* 3.saturation_treatment*) ///
		drop(*1.quartiles* *0.above_malf_median) order(*any_saturation_treatment* 3.saturation_treatment* 2.saturation_treatment*) label
	esttab est* using "Tables\muni_media_median_quartile.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N r2 Mean_Outcome SD_Outcome F_test_Q1 F_test_above F_test_Q3 F_test_Q4 ///
		F_test F_test_Q1_1 F_test_above_1 F_test_Q3_1 F_test_Q4_1 F_test_Q1_2 F_test_above_2 F_test_Q3_2 F_test_Q4_2, fmt(%9.0fc 2 2 2) ///
		labels("Observations" "$ R^2$" "Control outcome mean" "Control outcome std. dev." ///
		"Test: effect of treatment below median ($ p$ value)" "Test: effect of treatment above median ($ p$ value)" ///
		"Test: effect of treatment in Q3 ($ p$ value)" "Test: effect of treatment in Q4 ($ p$ value)" "Test: low = high ($ p$ value)" ///
		"Test: effect of low saturation below median ($ p$ value)" "Test: effect of low saturation above median ($ p$ value)" ///
		"Test: effect of low saturation in Q3 ($ p$ value)" "Test: effect of low saturation in Q4 ($ p$ value)" ///
		"Test: effect of high saturation in Q3 ($ p$ value)" "Test: effect of high saturation in Q4 ($ p$ value)")) ///
		starlevels(* .1 ** .05 *** .01) keep(1.any_saturation_treatment* 2.saturation_treatment* 3.saturation_treatment*) ///
		drop(*1.quartiles* *0.above_malf_median) order(*any_saturation_treatment* 3.saturation_treatment* 2.saturation_treatment*) label replace
	restore
}



*** Table I.8: Differential effects of Facebook ads on precinct-level municipal incumbent party vote share, by the number of local media outlets at precinct is covered by
*** Table I.9: Differential effects of Facebook ads on precinct-level municipal incumbent party vote share, by the number of non-local media outlets at precinct is covered by
quietly foreach s in local_cov_20_percent non_local_cov_20_percent {
	preserve
	** Prepare data
	* Recompute weights to weight segments equally in the subsample used for analysis
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	keep if e(sample)
	bysort code_INEGI segment : egen replacement = sum(muni_listanominal_2018)
	replace seg_listanominal_2018 = replacement
	replace segment_pooled_CK_sat_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_sat_prob)
	replace segment_pooled_CK_weight = muni_listanominal_2018 / (seg_listanominal_2018 * pooled_CK_prob)
	* Create logged versions of skewed covariates
	replace Recibidos = ln(Recibidos / muni_pop)
	replace mun_p_18ymas = ln(mun_p_18ymas)
	* Define the set of standardized linear controls
	global controls "Audit_Year Recibidos mun_p_18ymas muni_incumbent_vote_share muni_ave_schooling muni_illiterate muni_ave_occupants_per_room muni_ave_children_per_woman muni_share_elec_water_drainage muni_share_working_age muni_share_internet"
	g any_facebook_treatment_control = any_facebook_treatment
	g spillover_control = spillover
	g facebook_saturation_control = facebook_saturation
	global any_facebook_treatment_controls ""
	global spillover_controls ""
	global facebook_saturation_controls ""
	areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 any_facebook_treatment##quartiles spillover##quartiles [aweight=segment_pooled_CK_sat_weight], cluster(code_INEGI) a(id_block)
	foreach x of varlist $controls {
		sum `x' [aweight=segment_pooled_CK_sat_weight] if e(sample)==1
		replace `x' = (`x' - `r(mean)')/`r(sd)'
		global any_facebook_treatment_controls $any_facebook_treatment_controls any_facebook_treatment_control##c.`x'
		global spillover_controls $spillover_controls spillover_control##c.`x'
		global facebook_saturation_controls $facebook_saturation_controls i.facebook_saturation_control##c.`x'
	}
	** Regressions
	eststo clear
	foreach k in above_malf_median quartiles {
		* Facebook and spillover effects by saturation and quartile
		eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##`k'##c.`s' [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
		* Facebook and spillover effects by saturation and quartile, interactive controls
		eststo, title("muni_inc_vote_share") : areg muni_inc_vote_share_2018 muni_inc_vote_share_2015 i.facebook_saturation##`k'##c.`s' $facebook_saturation_controls [aweight=segment_pooled_CK_weight], cluster(code_INEGI) a(id_block)
		sum muni_inc_vote_share_2018 [aweight=segment_pooled_CK_weight] if e(sample) & any_saturation_treatment==0
		estadd scalar clusters = e(N_clust)
		estadd scalar Mean_Outcome = `r(mean)'
		estadd scalar SD_Outcome = `r(sd)'
	}
	** Make tables
	noisily estout, cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome, fmt(%9.0fc %9.0fc 2 2 2 3 3 3 3 3) labels("Observations" ///
		"Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev.")) starlevels(* .1 ** .05 *** .01) keep(*facebook_saturation*`s') label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" ///
		facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *1.quartiles* *0.above_malf_median*) ///
		order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*)
	esttab est* using "Tables\HEs_muni_inc_vote_share_by_median_and_quartile_by_`s'.tex", style(tex) prehead( ) posthead( ) prefoot(\\) postfoot( ) mlabels(, none) collabels(, none) eqlabels(, none) nonumbers ///
		cells(b(star fmt(3)) se(par)) stats(N clusters r2 Mean_Outcome SD_Outcome, fmt(%9.0fc %9.0fc 2 2 2 3 3 3 3 3) labels("Observations" ///
		"Number of municipality clusters" "$ R^2$" "Control outcome mean" "Control outcome std. dev.")) starlevels(* .1 ** .05 *** .01) keep(*facebook_saturation*`s') label ///
		varlabel(2.saturation_treatment "Low saturation" 3.saturation_treatment "High saturation" any_facebook_treatment "Facebook ads" ///
		facebook_treatment "Facebook ads (N)" facebook_common_treatment "Facebook ads (CK)") drop(0.* *1.quartiles* *0.above_malf_median*) ///
		order(4.facebook_saturation* 2.facebook_saturation* 3.facebook_saturation* 1.facebook_saturation*) replace
	restore
}



log close